From fb622ecffa68eb8e29305a54f4512fcd62a749d6 Mon Sep 17 00:00:00 2001 From: Charlton Liv <170700811+charltonliv@users.noreply.github.com> Date: Wed, 31 Jul 2024 01:24:40 +0800 Subject: [PATCH] wormchain: change ioutil to io and os (#3970) * ioutil to io and os * io to os --- node/pkg/node/node_test.go | 198 ++++++++++++++++++++++++++++++++++++- 1 file changed, 195 insertions(+), 3 deletions(-) diff --git a/node/pkg/node/node_test.go b/node/pkg/node/node_test.go index ecedf76573..2a5f6276b5 100644 --- a/node/pkg/node/node_test.go +++ b/node/pkg/node/node_test.go @@ -513,7 +513,7 @@ func waitForStatusServer(ctx context.Context, logger *zap.Logger, statusAddr str func TestMain(m *testing.M) { logger, _ = zap.NewDevelopment() readiness.NoPanic = true // otherwise we'd panic when running multiple guardians - retVal := m.Run() + retVal := m.Run() // Routine 2393 started here. logger.Info("test exiting", zap.Int("retVal", retVal)) os.Exit(retVal) } @@ -902,8 +902,125 @@ func TestWatcherConfigs(t *testing.T) { }, err: "L1finalizer does not exist. Please check the order of the watcher configurations in watcherConfigs.", }, + { + name: "watcher-noL1", + opts: []*GuardianOption{ + GuardianOptionWatchers([]watchers.WatcherConfig{ + &mock.WatcherConfig{ + NetworkID: "mock", + ChainID: vaa.ChainIDSolana, + L1FinalizerRequired: "something-that-does-not-exist", + }, + }, nil), + }, + err: "L1finalizer does not exist. Please check the order of the watcher configurations in watcherConfigs.", + }, + { + name: "watcher-noL1", + opts: []*GuardianOption{ + GuardianOptionWatchers([]watchers.WatcherConfig{ + &mock.WatcherConfig{ + NetworkID: "mock", + ChainID: vaa.ChainIDSolana, + L1FinalizerRequired: "something-that-does-not-exist", + }, + }, nil), + }, + err: "L1finalizer does not exist. Please check the order of the watcher configurations in watcherConfigs.", + }, + { + name: "watcher-noL1", + opts: []*GuardianOption{ + GuardianOptionWatchers([]watchers.WatcherConfig{ + &mock.WatcherConfig{ + NetworkID: "mock", + ChainID: vaa.ChainIDSolana, + L1FinalizerRequired: "something-that-does-not-exist", + }, + }, nil), + }, + err: "L1finalizer does not exist. Please check the order of the watcher configurations in watcherConfigs.", + }, + { + name: "watcher-noL1", + opts: []*GuardianOption{ + GuardianOptionWatchers([]watchers.WatcherConfig{ + &mock.WatcherConfig{ + NetworkID: "mock", + ChainID: vaa.ChainIDSolana, + L1FinalizerRequired: "something-that-does-not-exist", + }, + }, nil), + }, + err: "L1finalizer does not exist. Please check the order of the watcher configurations in watcherConfigs.", + }, + { + name: "watcher-noL1", + opts: []*GuardianOption{ + GuardianOptionWatchers([]watchers.WatcherConfig{ + &mock.WatcherConfig{ + NetworkID: "mock", + ChainID: vaa.ChainIDSolana, + L1FinalizerRequired: "something-that-does-not-exist", + }, + }, nil), + }, + err: "L1finalizer does not exist. Please check the order of the watcher configurations in watcherConfigs.", + }, + { + name: "watcher-noL1", + opts: []*GuardianOption{ + GuardianOptionWatchers([]watchers.WatcherConfig{ + &mock.WatcherConfig{ + NetworkID: "mock", + ChainID: vaa.ChainIDSolana, + L1FinalizerRequired: "something-that-does-not-exist", + }, + }, nil), + }, + err: "L1finalizer does not exist. Please check the order of the watcher configurations in watcherConfigs.", + }, + { + name: "watcher-noL1", + opts: []*GuardianOption{ + GuardianOptionWatchers([]watchers.WatcherConfig{ + &mock.WatcherConfig{ + NetworkID: "mock", + ChainID: vaa.ChainIDSolana, + L1FinalizerRequired: "something-that-does-not-exist", + }, + }, nil), + }, + err: "L1finalizer does not exist. Please check the order of the watcher configurations in watcherConfigs.", + }, + { + name: "watcher-noL1", + opts: []*GuardianOption{ + GuardianOptionWatchers([]watchers.WatcherConfig{ + &mock.WatcherConfig{ + NetworkID: "mock", + ChainID: vaa.ChainIDSolana, + L1FinalizerRequired: "something-that-does-not-exist", + }, + }, nil), + }, + err: "L1finalizer does not exist. Please check the order of the watcher configurations in watcherConfigs.", + }, + { + name: "watcher-noL1", + opts: []*GuardianOption{ + GuardianOptionWatchers([]watchers.WatcherConfig{ + &mock.WatcherConfig{ + NetworkID: "mock", + ChainID: vaa.ChainIDSolana, + L1FinalizerRequired: "something-that-does-not-exist", + }, + }, nil), + }, + err: "L1finalizer does not exist. Please check the order of the watcher configurations in watcherConfigs.", + }, } - runGuardianConfigTests(t, tc) + runGuardianConfigTests(t, tc) // These are the tests that have the data races. Some generate fatal errors. } func TestGuardianConfigs(t *testing.T) { @@ -930,6 +1047,78 @@ func TestGuardianConfigs(t *testing.T) { }, err: "Component db is already configured and cannot be configured a second time", }, + { + name: "double-configuration", + opts: []*GuardianOption{ + GuardianOptionDatabase(nil), + GuardianOptionDatabase(nil), + }, + err: "Component db is already configured and cannot be configured a second time", + }, + { + name: "double-configuration", + opts: []*GuardianOption{ + GuardianOptionDatabase(nil), + GuardianOptionDatabase(nil), + }, + err: "Component db is already configured and cannot be configured a second time", + }, + { + name: "double-configuration", + opts: []*GuardianOption{ + GuardianOptionDatabase(nil), + GuardianOptionDatabase(nil), + }, + err: "Component db is already configured and cannot be configured a second time", + }, + { + name: "double-configuration", + opts: []*GuardianOption{ + GuardianOptionDatabase(nil), + GuardianOptionDatabase(nil), + }, + err: "Component db is already configured and cannot be configured a second time", + }, + { + name: "double-configuration", + opts: []*GuardianOption{ + GuardianOptionDatabase(nil), + GuardianOptionDatabase(nil), + }, + err: "Component db is already configured and cannot be configured a second time", + }, + { + name: "double-configuration", + opts: []*GuardianOption{ + GuardianOptionDatabase(nil), + GuardianOptionDatabase(nil), + }, + err: "Component db is already configured and cannot be configured a second time", + }, + { + name: "double-configuration", + opts: []*GuardianOption{ + GuardianOptionDatabase(nil), + GuardianOptionDatabase(nil), + }, + err: "Component db is already configured and cannot be configured a second time", + }, + { + name: "double-configuration", + opts: []*GuardianOption{ + GuardianOptionDatabase(nil), + GuardianOptionDatabase(nil), + }, + err: "Component db is already configured and cannot be configured a second time", + }, + { + name: "double-configuration", + opts: []*GuardianOption{ + GuardianOptionDatabase(nil), + GuardianOptionDatabase(nil), + }, + err: "Component db is already configured and cannot be configured a second time", + }, } runGuardianConfigTests(t, tc) } @@ -939,6 +1128,7 @@ func runGuardianConfigTests(t *testing.T, testCases []testCaseGuardianConfig) { // because we're only instantiating the guardians and kill them right after they started running, 2s should be plenty of time const testTimeout = time.Second * 2 + // func() { // Test's main lifecycle context. rootCtx, rootCtxCancel := context.WithTimeout(context.Background(), testTimeout) defer rootCtxCancel() @@ -951,12 +1141,13 @@ func runGuardianConfigTests(t *testing.T, testCases []testCaseGuardianConfig) { defer close(fatalHook) zapLogger, zapObserver, _ := setupLogsCapture(t, zap.WithFatalHook(fatalHook)) - supervisor.New(rootCtx, zapLogger, func(ctx context.Context) error { + supervisor.New(rootCtx, zapLogger, func(ctx context.Context) error { // Routine 2620 started here. // Create a sub-context with cancel function that we can pass to G.run. ctx, ctxCancel := context.WithCancel(ctx) defer ctxCancel() if err := supervisor.Run(ctx, tc.name, NewGuardianNode(common.GoTest, nil).Run(ctxCancel, tc.opts...)); err != nil { + zapLogger.Info("Panicking", zap.Error(err)) panic(err) } @@ -987,6 +1178,7 @@ func runGuardianConfigTests(t *testing.T, testCases []testCaseGuardianConfig) { assert.NotEqual(t, rootCtx.Err(), context.DeadlineExceeded) assert.Equal(t, tc.err, "") // we only want to end up here if we did not expect an error. } + // }() } }