@@ -5,8 +5,10 @@ package utils
55
66import (
77 "context"
8+ "encoding/json"
89 "fmt"
910 "os"
11+ "path/filepath"
1012 "strings"
1113 "time"
1214
@@ -58,13 +60,36 @@ func RegisterPingTest() {
5860 })
5961}
6062
61- // RegisterNodeRun registers a before suite that starts an AvalancheGo process to use for the e2e tests
62- // and an after suite that stops the AvalancheGo process
63+ // At boot time subnets are created, one for each test suite. This global
64+ // variable has all the subnets IDs that can be used.
65+ //
66+ // One process creates the AvalancheGo node and all the subnets, and these
67+ // subnets IDs are passed to all other processes and stored in this global
68+ // variable
69+ var BlockchainIDs map [string ]string
70+
71+ // Timeout to boot the AvalancheGo node
72+ var bootAvalancheNodeTimeout = 5 * time .Minute
73+
74+ // Timeout for the health API to check the AvalancheGo is ready
75+ var healthCheckTimeout = 5 * time .Second
76+
6377func RegisterNodeRun () {
64- // BeforeSuite starts an AvalancheGo process to use for the e2e tests
78+ // Keep track of the AvalancheGo external bash script, it is null for most
79+ // processes except the first process that starts AvalancheGo
6580 var startCmd * cmd.Cmd
66- _ = ginkgo .BeforeSuite (func () {
67- ctx , cancel := context .WithTimeout (context .Background (), time .Minute )
81+
82+ // Our test suite runs in a separated processes, ginkgo hasI
83+ // SynchronizedBeforeSuite() which is promised to run once, and its output is
84+ // passed over to each worker.
85+ //
86+ // In here an AvalancheGo node instance is started, and subnets are created for
87+ // each test case. Each test case has its own subnet, therefore all tests can
88+ // run in parallel without any issue.
89+ //
90+ // This function also compiles all the solidity contracts
91+ var _ = ginkgo .SynchronizedBeforeSuite (func () []byte {
92+ ctx , cancel := context .WithTimeout (context .Background (), bootAvalancheNodeTimeout )
6893 defer cancel ()
6994
7095 wd , err := os .Getwd ()
@@ -76,16 +101,34 @@ func RegisterNodeRun() {
76101
77102 // Assumes that startCmd will launch a node with HTTP Port at [utils.DefaultLocalNodeURI]
78103 healthClient := health .NewClient (DefaultLocalNodeURI )
79- healthy , err := health .AwaitReady (ctx , healthClient , 5 * time . Second , nil )
104+ healthy , err := health .AwaitReady (ctx , healthClient , healthCheckTimeout , nil )
80105 gomega .Expect (err ).Should (gomega .BeNil ())
81106 gomega .Expect (healthy ).Should (gomega .BeTrue ())
82107 log .Info ("AvalancheGo node is healthy" )
108+
109+ blockchainIds := make (map [string ]string )
110+ files , err := filepath .Glob ("./tests/precompile/genesis/*.json" )
111+ gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
112+
113+ for _ , file := range files {
114+ basename := filepath .Base (file )
115+ index := basename [:len (basename )- 5 ]
116+ blockchainIds [index ] = CreateNewSubnet (ctx , file )
117+ }
118+
119+ blockchainIDsBytes , err := json .Marshal (blockchainIds )
120+ gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
121+ return blockchainIDsBytes
122+ }, func (data []byte ) {
123+ err := json .Unmarshal (data , & BlockchainIDs )
124+ gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
83125 })
84126
85- ginkgo .AfterSuite (func () {
127+ // SynchronizedAfterSuite() takes two functions, the first runs after each test suite is done and the second
128+ // function is executed once when all the tests are done. This function is used
129+ // to gracefully shutdown the AvalancheGo node.
130+ var _ = ginkgo .SynchronizedAfterSuite (func () {}, func () {
86131 gomega .Expect (startCmd ).ShouldNot (gomega .BeNil ())
87132 gomega .Expect (startCmd .Stop ()).Should (gomega .BeNil ())
88- // TODO add a new node to bootstrap off of the existing node and ensure it can bootstrap all subnets
89- // created during the test
90133 })
91134}
0 commit comments