Skip to content

✨ [pkg/test] Add context to ConcurrentT. #112

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
merged 2 commits into from
Jun 17, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
✨ [pkg/test] Add error messages.
Now, whenever a stage fails or the test context expires, a t.Errorf()
call is made.

Signed-off-by: Steffen Rattay <steffen@perun.network>
  • Loading branch information
RmbRT committed Jun 17, 2021
commit 9cb394262aef2f636698eb8dd74152a8dce14699
10 changes: 9 additions & 1 deletion pkg/test/concurrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ func (t *ConcurrentT) Wait(names ...string) {
stage := t.getStage(name)
select {
case <-t.ctx.Done():
t.failNowMutex.Lock()
t.t.Errorf("Wait for stage %s: %v", name, t.ctx.Err())
t.failNowMutex.Unlock()
t.FailNow()
case <-stage.wg.WaitCh():
if stage.failed.IsSet() {
Expand Down Expand Up @@ -245,12 +248,17 @@ func (t *ConcurrentT) StageN(name string, goroutines int, fn func(ConcT)) {

// If it did not terminate, just abort the test.
if !ok {
t.failNowMutex.Lock()
t.t.Errorf("Stage %s: %v", name, t.ctx.Err())
t.failNowMutex.Unlock()
t.FailNow()
}

// If it is a panic or Goexit from certain contexts, print stack trace.
if _, ok := abort.(*Panic); ok || shouldPrintStack(abort.Stack()) {
print("\n", abort.String())
t.failNowMutex.Lock()
t.t.Errorf("Stage %s: %s", name, abort.String())
t.failNowMutex.Unlock()
}
t.FailNow()
}
Expand Down