Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fasmat committed Feb 26, 2024
1 parent 4a9a3ae commit 1bdf71b
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,16 +417,16 @@ func TestSpacemeshApp_NodeService(t *testing.T) {

signer, err := signing.NewEdSigner()
require.NoError(t, err)
app.signers = append(app.signers, signer)
app.signers = []*signing.EdSigner{signer}

mesh, err := mocknet.WithNPeers(1)
require.NoError(t, err)
h, err := p2p.Upgrade(mesh.Hosts()[0])
require.NoError(t, err)
app.host = h

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
appCtx, appCancel := context.WithCancel(context.Background())
defer appCancel()

run := func(c *cobra.Command, args []string) error {
// Give the error channel a buffer
Expand All @@ -442,9 +442,12 @@ func TestSpacemeshApp_NodeService(t *testing.T) {
// This will block. We need to run the full app here to make sure that
// the various services are reporting events correctly. This could probably
// be done more surgically, and we don't need _all_ of the services.
return app.Start(context.Background())
return app.Start(appCtx)
}

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

// Run the app in a goroutine. As noted above, it blocks if it succeeds.
// If there's an error in the args, it will return immediately.
var eg errgroup.Group
Expand All @@ -455,7 +458,7 @@ func TestSpacemeshApp_NodeService(t *testing.T) {
return nil
})

<-app.started
<-app.Started()
conn, err := grpc.DialContext(
ctx,
app.grpcPublicServer.BoundAddress,
Expand Down Expand Up @@ -519,6 +522,7 @@ func TestSpacemeshApp_NodeService(t *testing.T) {

// Cleanup stops all services and thereby the app
<-app.Started() // prevents races when app is not started yet
appCancel()
app.Cleanup(context.Background())

// Wait for everything to stop cleanly before ending test
Expand All @@ -527,8 +531,6 @@ func TestSpacemeshApp_NodeService(t *testing.T) {

// E2E app test of the transaction service.
func TestSpacemeshApp_TransactionService(t *testing.T) {
r := require.New(t)

listener := "127.0.0.1:14236"

app := New(WithLog(logtest.New(t)))
Expand All @@ -537,12 +539,15 @@ func TestSpacemeshApp_TransactionService(t *testing.T) {
app.Config = &cfg

signer, err := signing.NewEdSigner()
r.NoError(err)
app.signers = append(app.signers, signer)
require.NoError(t, err)
app.signers = []*signing.EdSigner{signer}
address := wallet.Address(signer.PublicKey().Bytes())

appCtx, appCancel := context.WithCancel(context.Background())
defer appCancel()

run := func(c *cobra.Command, args []string) error {
r.NoError(app.Initialize())
require.NoError(t, app.Initialize())

// GRPC configuration
app.Config.API.PublicListener = listener
Expand Down Expand Up @@ -572,7 +577,7 @@ func TestSpacemeshApp_TransactionService(t *testing.T) {
// This will block. We need to run the full app here to make sure that
// the various services are reporting events correctly. This could probably
// be done more surgically, and we don't need _all_ of the services.
return app.Start(context.Background())
return app.Start(appCtx)
}

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
Expand All @@ -584,8 +589,8 @@ func TestSpacemeshApp_TransactionService(t *testing.T) {
wg.Add(1)
go func() {
str, err := testArgs(ctx, cmdWithRun(run))
r.Empty(str)
r.NoError(err)
require.Empty(t, str)
require.NoError(t, err)
wg.Done()
}()

Expand All @@ -605,8 +610,8 @@ func TestSpacemeshApp_TransactionService(t *testing.T) {
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
)
r.NoError(err)
t.Cleanup(func() { r.NoError(conn.Close()) })
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, conn.Close()) })
c := pb.NewTransactionServiceClient(conn)

tx1 := types.NewRawTx(
Expand Down Expand Up @@ -653,6 +658,7 @@ func TestSpacemeshApp_TransactionService(t *testing.T) {

// This stops the app
// Cleanup stops all services and thereby the app
appCancel()
app.Cleanup(context.Background())

// Wait for it to stop
Expand Down Expand Up @@ -1157,7 +1163,7 @@ func TestAdminEvents_MultiSmesher(t *testing.T) {
})
t.Cleanup(func() { assert.NoError(t, eg.Wait()) })

<-app.started
<-app.Started()
for _, signer := range app.signers {
mgr, err := activation.NewPostSetupManager(
cfg.POST,
Expand Down

0 comments on commit 1bdf71b

Please sign in to comment.