diff --git a/gno.land/pkg/integration/testing_integration.go b/gno.land/pkg/integration/testing_integration.go index be87ea1135a..c007b62e3c5 100644 --- a/gno.land/pkg/integration/testing_integration.go +++ b/gno.land/pkg/integration/testing_integration.go @@ -10,6 +10,7 @@ import ( "strings" "sync" "testing" + "time" "github.com/gnolang/gno/gno.land/pkg/gnoland" "github.com/gnolang/gno/tm2/pkg/bft/config" @@ -115,9 +116,8 @@ func SetupGnolandTestScript(t *testing.T, txtarDir string) testscript.Params { // Create the Node nodecfg := gnoland.NewInMemoryNodeConfig(cfg) - node, err := gnoland.NewInMemoryNode(logger, nodecfg) - if err != nil { - err = fmt.Errorf("unable to start node: %w", err) + var node *node.Node + if node, err = execInMemoryGnoland(ts); err != nil { break } @@ -133,6 +133,7 @@ func SetupGnolandTestScript(t *testing.T, txtarDir string) testscript.Params { } }) + // Register cleanup. nodes[sid] = &testNode{ Node: node, @@ -208,6 +209,27 @@ func SetupGnolandTestScript(t *testing.T, txtarDir string) testscript.Params { } } + +func execInMemoryGnoland(ts *testscript.Params) (*node.Node, error) { + node, err = gnoland.NewInMemoryNode(logger, nodecfg) + if err != nil { + return nil, fmt.Errorf("unable to create node: %w", err) + } + + if err = node.Start(); err = nil { + return nil, fmt.Errorf("unable to start node: %w", err) + } + + select { + case <-time.After(time.Second * 6): + _ = node.Close() + return errors.New("timeout while waiting for the node to start") + case <-waitForNodeReadiness(node): // ok + return nil + } +} + + func getSessionID(ts *testscript.TestScript) string { works := ts.Getenv("WORK") sum := crc32.ChecksumIEEE([]byte(works))