Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
brynbellomy committed Oct 24, 2021
1 parent 669720a commit 2c9038b
Show file tree
Hide file tree
Showing 11 changed files with 1,604 additions and 296 deletions.
28 changes: 20 additions & 8 deletions internal/testutils/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,44 @@ func NewAwaiter() Awaiter { return make(Awaiter, 10) }

func (a Awaiter) ItHappened() { a <- struct{}{} }

func (a Awaiter) AwaitOrFail(t testing.TB, durationParams ...time.Duration) {
func (a Awaiter) AwaitOrFail(t testing.TB, params ...interface{}) {
t.Helper()

duration := 10 * time.Second
if len(durationParams) > 0 {
duration = durationParams[0]
msg := ""
for _, p := range params {
switch p := p.(type) {
case time.Duration:
duration = p
case string:
msg = p
}
}

select {
case <-a:
case <-time.After(duration):
t.Fatal("Timed out waiting for Awaiter to get ItHappened")
t.Fatalf("Timed out waiting for Awaiter to get ItHappened: %v", msg)
}
}

func (a Awaiter) NeverHappenedOrFail(t testing.TB, durationParams ...time.Duration) {
func (a Awaiter) NeverHappenedOrFail(t testing.TB, params ...interface{}) {
t.Helper()

duration := 10 * time.Second
if len(durationParams) > 0 {
duration = durationParams[0]
msg := ""
for _, p := range params {
switch p := p.(type) {
case time.Duration:
duration = p
case string:
msg = p
}
}

select {
case <-a:
t.Fatal("should not happen")
t.Fatalf("should not happen: %v", msg)
case <-time.After(duration):
}
}
Loading

0 comments on commit 2c9038b

Please sign in to comment.