overlaycache's DB access modified to use transaction (#1596)

This commit is contained in:
aligeti 2019-03-29 09:46:17 -04:00 committed by GitHub
parent 9dbc7c719e
commit ea22411cac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,7 @@ package overlay_test
import ( import (
"context" "context"
"strconv"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -264,6 +265,8 @@ func testDatabase(ctx context.Context, t *testing.T, cache overlay.DB) {
{ // TestUpdateBatchExists { // TestUpdateBatchExists
nodeID1 := storj.NodeID{255, 1} nodeID1 := storj.NodeID{255, 1}
nodeID2 := storj.NodeID{255, 2} nodeID2 := storj.NodeID{255, 2}
nodeID3 := storj.NodeID{255, 3}
nodeID4 := storj.NodeID{255, 4}
auditSuccessCount1 := int64(4) auditSuccessCount1 := int64(4)
auditCount1 := int64(10) auditCount1 := int64(10)
@ -340,5 +343,19 @@ func testDatabase(ctx context.Context, t *testing.T, cache overlay.DB) {
assert.EqualValues(t, newUptimeRatio1, stats1.UptimeRatio) assert.EqualValues(t, newUptimeRatio1, stats1.UptimeRatio)
assert.EqualValues(t, newAuditRatio2, stats2.AuditSuccessRatio) assert.EqualValues(t, newAuditRatio2, stats2.AuditSuccessRatio)
assert.EqualValues(t, newUptimeRatio2, stats2.UptimeRatio) assert.EqualValues(t, newUptimeRatio2, stats2.UptimeRatio)
concurrency := 100
t.Run("CreateEntryIfNotExists", func(t *testing.T) {
nodes := []*pb.Node{&pb.Node{Id: nodeID1}, &pb.Node{Id: nodeID2}, &pb.Node{Id: nodeID3}, &pb.Node{Id: nodeID4}}
for P := 0; P < concurrency; P++ {
t.Run("#"+strconv.Itoa(P), func(t *testing.T) {
t.Parallel()
for _, node := range nodes {
_, err := cache.CreateEntryIfNotExists(ctx, node)
assert.NoError(t, err)
}
})
}
})
} }
} }