From 00b2dfa3137cac4caa7b52481838540fb4886929 Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Thu, 30 Apr 2020 15:00:06 +0300 Subject: [PATCH] storagenode/orders: fix TestDB and TestCleanArchive Tests were relying on too exact time values. Change-Id: I83aa0e815b06372a65ec2d62b23df86051050d19 --- storagenode/orders/db_test.go | 16 ++++++++++------ storagenode/orders/service_test.go | 3 ++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/storagenode/orders/db_test.go b/storagenode/orders/db_test.go index 2ac4594f6..2e654b37b 100644 --- a/storagenode/orders/db_test.go +++ b/storagenode/orders/db_test.go @@ -40,7 +40,7 @@ func TestDB(t *testing.T) { require.NoError(t, err) require.Len(t, emptyArchive, 0) - now := time.Now() + before := time.Now().Add(-time.Second) piecePublicKey, piecePrivateKey, err := storj.NewPieceKey() require.NoError(t, err) @@ -57,9 +57,9 @@ func TestDB(t *testing.T) { PieceId: piece, Limit: 100, Action: pb.PieceAction_GET, - OrderCreation: now.AddDate(0, 0, -1), - PieceExpiration: now, - OrderExpiration: now, + OrderCreation: before.AddDate(0, 0, -1), + PieceExpiration: before, + OrderExpiration: before, }) require.NoError(t, err) @@ -173,6 +173,8 @@ func TestDB(t *testing.T) { }, }, archived, cmp.Comparer(pb.Equal))) + time.Sleep(time.Second) + // with 1 hour ttl, archived order should not be deleted n, err := db.Orders().CleanArchive(ctx, time.Hour) require.NoError(t, err) @@ -189,13 +191,15 @@ func TestDB_Trivial(t *testing.T) { storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) { satelliteID, serial := testrand.NodeID(), testrand.SerialNumber() + before := time.Now().Add(-time.Second) + { // Ensure Enqueue works at all err := db.Orders().Enqueue(ctx, &orders.Info{ Order: &pb.Order{}, Limit: &pb.OrderLimit{ SatelliteId: satelliteID, SerialNumber: serial, - OrderExpiration: time.Now(), + OrderExpiration: before, }, }) require.NoError(t, err) @@ -216,7 +220,7 @@ func TestDB_Trivial(t *testing.T) { } { // Ensure Archive works at all - err := db.Orders().Archive(ctx, time.Now().UTC(), orders.ArchiveRequest{satelliteID, serial, orders.StatusAccepted}) + err := db.Orders().Archive(ctx, before.UTC(), orders.ArchiveRequest{satelliteID, serial, orders.StatusAccepted}) require.NoError(t, err) } diff --git a/storagenode/orders/service_test.go b/storagenode/orders/service_test.go index 7828d12a3..aa502555f 100644 --- a/storagenode/orders/service_test.go +++ b/storagenode/orders/service_test.go @@ -22,7 +22,7 @@ func TestCleanArchive(t *testing.T) { SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0, Reconfigure: testplanet.Reconfigure{ StorageNode: func(index int, config *storagenode.Config) { - config.Storage2.Orders.ArchiveTTL = 24 * time.Hour + config.Storage2.Orders.ArchiveTTL = 12 * time.Hour }, }, }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { @@ -80,6 +80,7 @@ func TestCleanArchive(t *testing.T) { archived, err := node.DB.Orders().ListArchived(ctx, 10) require.NoError(t, err) + require.Len(t, archived, 1) require.Equal(t, archived[0].Limit.SerialNumber, serialNumber1) })