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.
This commit is contained in:
Conner Fromknecht 2018-06-27 14:37:23 -07:00
parent ec7cfc6906
commit e85fa1af96
No known key found for this signature in database
GPG Key ID: 39DE78FBE6ACB0EF

@ -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)
}