node/near/test: bugfix don't write to testCase.doneC from setupAndRun

This commit is contained in:
tbjump 2023-05-24 00:44:01 +00:00 committed by tbjump
parent 42e8121d7d
commit c20c3c667d
1 changed files with 7 additions and 13 deletions

View File

@ -104,6 +104,7 @@ func (testCase *testCase) run(ctx context.Context) error {
// Run the watcher
if err := supervisor.Run(ctx, "nearwatch", w.Run); err != nil {
testCase.doneC <- err
return err
}
@ -184,7 +185,7 @@ func (testCase *testCase) setupAndRun(logger *zap.Logger) {
rootCtx, rootCtxCancel := context.WithTimeout(context.Background(), testCase.timeout)
defer rootCtxCancel()
testCase.doneC = make(chan error, 1)
testCase.doneC = make(chan error)
// run the test
supervisor.New(rootCtx, logger, func(ctx context.Context) error {
@ -199,18 +200,11 @@ func (testCase *testCase) setupAndRun(logger *zap.Logger) {
return nil
}, supervisor.WithPropagatePanic)
// wait for result or timeout
for {
select {
case <-rootCtx.Done():
testCase.doneC <- rootCtx.Err()
case err := <-testCase.doneC:
rootCtxCancel()
assert.NotEqual(testCase.t, err, context.DeadlineExceeded) // throw an error if timeout
assert.NoError(testCase.t, err)
return
}
}
// wait for result or timeout. Note that if ctx.Done(), then the test runner will send to testCase.doneC as well, so we don't need to check for it here.
err := <-testCase.doneC
rootCtxCancel()
assert.NotEqual(testCase.t, err, context.DeadlineExceeded) // throw an error if timeout
assert.NoError(testCase.t, err)
}
// TestWatcherSimple() tests the most simple case: "final" API only retruns one block which contains a Wormhole transaction. No re-observation requests.