From 67306d296b93222c0702e6d1aec7a42339b5e223 Mon Sep 17 00:00:00 2001 From: Alexander Leitner Date: Thu, 1 Nov 2018 12:40:26 -0400 Subject: [PATCH] Bandwidth fix (#567) * Don't scan into nil --- pkg/piecestore/rpc/server/psdb/psdb.go | 2 +- pkg/piecestore/rpc/server/psdb/psdb_test.go | 47 ++++++++++++++++++--- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/pkg/piecestore/rpc/server/psdb/psdb.go b/pkg/piecestore/rpc/server/psdb/psdb.go index e8ce587d7..bf0d99541 100644 --- a/pkg/piecestore/rpc/server/psdb/psdb.go +++ b/pkg/piecestore/rpc/server/psdb/psdb.go @@ -281,7 +281,7 @@ func (db *DB) GetBandwidthAllocations() (map[string][]*Agreement, error) { agreements := make(map[string][]*Agreement) for rows.Next() { - var agreement *Agreement + agreement := &Agreement{} var satellite string err := rows.Scan(&satellite, &agreement.Agreement, &agreement.Signature) if err != nil { diff --git a/pkg/piecestore/rpc/server/psdb/psdb_test.go b/pkg/piecestore/rpc/server/psdb/psdb_test.go index 8a1d12894..6a2571cb8 100644 --- a/pkg/piecestore/rpc/server/psdb/psdb_test.go +++ b/pkg/piecestore/rpc/server/psdb/psdb_test.go @@ -136,10 +136,14 @@ func TestHappyPath(t *testing.T) { } }) - bandwidthAllocation := func(total int64) []byte { + bandwidthAllocation := func(satelliteID string, total int64) []byte { return serialize(t, &pb.RenterBandwidthAllocation_Data{ - PayerAllocation: &pb.PayerBandwidthAllocation{}, - Total: total, + PayerAllocation: &pb.PayerBandwidthAllocation{ + Data: serialize(t, &pb.PayerBandwidthAllocation_Data{ + SatelliteId: []byte(satelliteID), + }), + }, + Total: total, }) } @@ -147,19 +151,19 @@ func TestHappyPath(t *testing.T) { allocationTests := []*pb.RenterBandwidthAllocation{ { Signature: []byte("signed by test"), - Data: bandwidthAllocation(0), + Data: bandwidthAllocation("AB", 0), }, { Signature: []byte("signed by sigma"), - Data: bandwidthAllocation(10), + Data: bandwidthAllocation("AB", 10), }, { Signature: []byte("signed by sigma"), - Data: bandwidthAllocation(98), + Data: bandwidthAllocation("AB", 98), }, { Signature: []byte("signed by test"), - Data: bandwidthAllocation(3), + Data: bandwidthAllocation("AB", 3), }, } @@ -193,6 +197,35 @@ func TestHappyPath(t *testing.T) { }) } }) + + t.Run("Get all Bandwidth Allocations", func(t *testing.T) { + for P := 0; P < concurrency; P++ { + t.Run("#"+strconv.Itoa(P), func(t *testing.T) { + t.Parallel() + + agreementGroups, err := db.GetBandwidthAllocations() + if err != nil { + t.Fatal(err) + } + + found := false + for _, agreements := range agreementGroups { + for _, agreement := range agreements { + for _, test := range allocationTests { + if bytes.Equal(agreement.Agreement, test.Data) { + found = true + break + } + } + } + } + + if !found { + t.Fatal("did not find added bandwidth allocation") + } + }) + } + }) } func TestBandwidthUsage(t *testing.T) {