Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - fix flaky test: TestSpacemeshApp_NodeService #4728

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions activation/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,19 @@
if err != nil {
b.log.With().Panic("failed to fetch commitment ATX ID.", log.Err(err))
}
if err := b.validator.Post(ctx, types.EpochID(0), b.nodeID, commitmentAtxId, post, metadata, b.postSetupProvider.LastOpts().NumUnits); err != nil {
err = b.validator.Post(ctx, types.EpochID(0), b.nodeID, commitmentAtxId, post, metadata, b.postSetupProvider.LastOpts().NumUnits)
switch {
case errors.Is(err, context.Canceled):
// If the context was canceled, we don't want to emit or log errors just propagate the cancellation signal.
return err
case err != nil:

Check warning on line 328 in activation/activation.go

View check run for this annotation

Codecov / codecov/patch

activation/activation.go#L325-L328

Added lines #L325 - L328 were not covered by tests
events.EmitInvalidPostProof()
b.log.With().Fatal("initial POST proof is invalid. Probably the initialized POST data is corrupted. Please verify the data with postcli and regenerate the corrupted files.", log.Err(err))
return err
default:
b.initialPost = post
return nil
}
b.initialPost = post
return nil
}

func (b *Builder) receivePendingPoetClients() *[]PoetProvingServiceClient {
Expand Down
3 changes: 2 additions & 1 deletion node/bad_peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ func NewApp(conf *config.Config) (*App, error) {
WithConfig(conf),
WithLog(log.RegisterHooks(
log.NewWithLevel("", zap.NewAtomicLevelAt(zapcore.DebugLevel)),
events.EventHook())),
events.EventHook()),
),
fasmat marked this conversation as resolved.
Show resolved Hide resolved
)

var err error
Expand Down
12 changes: 8 additions & 4 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@
// NOTE(dshulyak) this needs to be max level so that child logger can can be current level or below.
// otherwise it will fail later when child logger will try to increase level.
WithLog(log.RegisterHooks(
log.NewWithLevel("", zap.NewAtomicLevelAt(zapcore.DebugLevel)),
events.EventHook())),
log.NewWithLevel("node", zap.NewAtomicLevelAt(zap.InfoLevel)),
events.EventHook()),
),

Check warning on line 135 in node/node.go

View check run for this annotation

Codecov / codecov/patch

node/node.go#L133-L135

Added lines #L133 - L135 were not covered by tests
)

run := func(ctx context.Context) error {
Expand Down Expand Up @@ -293,8 +294,7 @@
for _, opt := range opts {
opt(app)
}
lvl := zap.NewAtomicLevelAt(zap.InfoLevel)
log.SetupGlobal(app.log.SetLevel(&lvl))
log.SetupGlobal(app.log)
types.SetNetworkHRP(app.Config.NetworkHRP)
return app
}
Expand Down Expand Up @@ -1192,6 +1192,10 @@
}

events.CloseEventReporter()
// SetGrpcLogger unfortunately is global
// this ensures that a test-logger isn't used after the app shuts down
// by e.g. a grpc connection to the node that is still open - like in TestSpacemeshApp_NodeService
grpczap.SetGrpcLoggerV2(grpclog, log.NewNop().Zap())
}

// LoadOrCreateEdSigner either loads a previously created ed identity for the node or creates a new one if not exists.
Expand Down
10 changes: 4 additions & 6 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,24 +410,22 @@ func TestSpacemeshApp_JsonService(t *testing.T) {

// E2E app test of the stream endpoints in the NodeService.
func TestSpacemeshApp_NodeService(t *testing.T) {
t.Skip("flaky on macos-latest: https://github.com/spacemeshos/go-spacemesh/issues/4729")
// errlog should be used only for testing.
logger := logtest.New(t)
errlog := log.RegisterHooks(logtest.New(t, zap.ErrorLevel), events.EventHook())
logger := logtest.New(t, zapcore.ErrorLevel)
errlog := log.RegisterHooks(logger, events.EventHook()) // errlog is used to simulate errors in the app

// Use a unique port
port := 1240

app := New(WithLog(logger))
app.Config = getTestDefaultConfig(t)
app.Config.SMESHING.CoinbaseAccount = types.GenerateAddress([]byte{1}).String()
app.Config.SMESHING.Opts.DataDir, _ = os.MkdirTemp("", "sm-app-test-post-datadir")
app.Config.SMESHING.Opts.DataDir = t.TempDir()

clock, err := timesync.NewClock(
timesync.WithLayerDuration(1*time.Second),
timesync.WithTickInterval(100*time.Millisecond),
timesync.WithGenesisTime(time.Now()),
timesync.WithLogger(logtest.New(t)),
timesync.WithLogger(logger),
)
require.NoError(t, err)
app.clock = clock
Expand Down