From 9a621d434b64d8a5a02cda806a2e7373179ef815 Mon Sep 17 00:00:00 2001 From: "M. J. Fromberger" Date: Fri, 27 Aug 2021 11:58:36 -0700 Subject: [PATCH] Add a -debug flag to the test for manual inspection --- state/indexer/sink/psql/psql_test.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/state/indexer/sink/psql/psql_test.go b/state/indexer/sink/psql/psql_test.go index 02e29f3bc..6f8cb4f5d 100644 --- a/state/indexer/sink/psql/psql_test.go +++ b/state/indexer/sink/psql/psql_test.go @@ -4,9 +4,11 @@ import ( "context" "database/sql" "errors" + "flag" "fmt" "io/ioutil" "os" + "os/signal" "testing" "time" @@ -27,9 +29,13 @@ import ( // Verify that the type satisfies the EventSink interface. var _ indexer.EventSink = (*EventSink)(nil) -var db *sql.DB -var resource *dockertest.Resource -var chainID = "test-chainID" +var ( + doDebug = flag.Bool("debug", false, "If true, pause at teardown") + + db *sql.DB + resource *dockertest.Resource + chainID = "test-chainID" +) const ( user = "postgres" @@ -287,7 +293,9 @@ func mustSetupDB(t *testing.T) *dockertest.Pool { // Set the container to expire in a minute to avoid orphaned containers // hanging around - _ = resource.Expire(60) + if !*doDebug { + _ = resource.Expire(60) + } conn := fmt.Sprintf(dsn, user, password, resource.GetPort(port+"/tcp"), dbName) @@ -311,6 +319,16 @@ func mustSetupDB(t *testing.T) *dockertest.Pool { // mustTeardown purges the pool and closes the test database. func mustTeardown(t *testing.T, pool *dockertest.Pool) { t.Helper() + if *doDebug { + t.Log("Teardown paused: Send SIGINT to resume") + ch := make(chan os.Signal, 1) + signal.Notify(ch, os.Interrupt) + select { + case <-ch: + break + } + t.Log("Resumed teardown") + } require.Nil(t, pool.Purge(resource)) require.Nil(t, db.Close()) }