From 78439416c0dccaf3edaed00a970b6278bf762baa Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Fri, 27 Jul 2018 02:27:02 -0700 Subject: [PATCH] htlcswitch/circuit_test: test for relaxed DeleteCircuits Modify unit tests to expect success when removing already-deleted circuits, as well as test that extra circuit deletions are ignored. --- htlcswitch/circuit_test.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/htlcswitch/circuit_test.go b/htlcswitch/circuit_test.go index 046c9fde..b693ebe7 100644 --- a/htlcswitch/circuit_test.go +++ b/htlcswitch/circuit_test.go @@ -483,8 +483,9 @@ func TestCircuitMapPersistence(t *testing.T) { // Removing already-removed circuit should return an error. err = circuitMap.DeleteCircuits(circuit1.Incoming) - if err == nil { - t.Fatal("Remove did not return expected not found error") + if err != nil { + t.Fatal("Unexpected failure when deleting already "+ + "deleted circuit: %v", err) } // Verify that nothing related to hash1 has changed @@ -518,10 +519,17 @@ func TestCircuitMapPersistence(t *testing.T) { assertNumCircuitsWithHash(t, circuitMap, hash2, 0) assertNumCircuitsWithHash(t, circuitMap, hash3, 1) - // Remove last remaining circuit with payment hash hash3. - err = circuitMap.DeleteCircuits(circuit3.Incoming) + // In removing the final circuit, we will try and remove all other known + // circuits as well. Any circuits that are unknown to the circuit map + // will be ignored, and only circuit 3 should be cause any change in the + // state. + err = circuitMap.DeleteCircuits( + circuit1.Incoming, circuit2.Incoming, + circuit3.Incoming, circuit4.Incoming, + ) if err != nil { - t.Fatalf("Remove returned unexpected error: %v", err) + t.Fatalf("Unexpected failure when removing circuit while also "+ + "deleting already deleted circuits: %v", err) } // Check that the circuit map is empty, even after restarting.