From e85fa1af9651ce5cdd417f53cbf4444fef472389 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 27 Jun 2018 14:37:23 -0700 Subject: [PATCH] htlcswitch/decayedlog_test: fix bug in gc unit test This commit fixes a bug in the TestDecayedLogPersistentGarbageCollector unit test. The test generates a second hash prefix, which is never added to the log, and used to query for the final existence check. This commit reverts the behavior so that the same hash prefix is used throughout the test. --- htlcswitch/decayedlog_test.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/htlcswitch/decayedlog_test.go b/htlcswitch/decayedlog_test.go index 63dd84c2..2afcdda4 100644 --- a/htlcswitch/decayedlog_test.go +++ b/htlcswitch/decayedlog_test.go @@ -152,18 +152,27 @@ func TestDecayedLogPersistentGarbageCollector(t *testing.T) { t.Fatalf("Unable to store in channeldb: %v", err) } - // Wait for database write (GC is in a goroutine) - time.Sleep(500 * time.Millisecond) + // The hash prefix should be retrievable from the decayed log. + _, err = d.Get(hashedSecret) + if err != nil { + t.Fatalf("Get failed - received unexpected error upon Get: %v", err) + } // Shut down DecayedLog and the garbage collector along with it. d.Stop() - d2, notifier2, hashedSecret2, err := startup(dbPath, true) + d2, notifier2, _, err := startup(dbPath, true) if err != nil { t.Fatalf("Unable to restart DecayedLog: %v", err) } defer shutdown(dbPath, d2) + // Check that the hash prefix still exists in the new db instance. + _, err = d2.Get(hashedSecret) + if err != nil { + t.Fatalf("Get failed - received unexpected error upon Get: %v", err) + } + // Send a block notification to the garbage collector that expires // the stored CLTV. notifier2.epochChan <- &chainntnfs.BlockEpoch{ @@ -174,10 +183,7 @@ func TestDecayedLogPersistentGarbageCollector(t *testing.T) { time.Sleep(500 * time.Millisecond) // Assert that hashedSecret is not in the sharedHashBucket - _, err = d2.Get(hashedSecret2) - if err == nil { - t.Fatalf("CLTV was not deleted") - } + _, err = d2.Get(hashedSecret) if err != sphinx.ErrLogEntryNotFound { t.Fatalf("Get failed - received unexpected error upon Get: %v", err) }