Skip to content

Commit

Permalink
wormchain: change ioutil to io and os (wormhole-foundation#3970)
Browse files Browse the repository at this point in the history
* ioutil to io and os

* io to os
  • Loading branch information
charltonliv authored and bruce-riley committed Jul 30, 2024
1 parent 1c06d70 commit fb622ec
Showing 1 changed file with 195 additions and 3 deletions.
198 changes: 195 additions & 3 deletions node/pkg/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
}
Expand All @@ -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()
Expand All @@ -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)
}

Expand Down Expand Up @@ -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.
}
// }()
}
}

Expand Down

0 comments on commit fb622ec

Please sign in to comment.