Skip to content

Commit

Permalink
oversight: deflake test mean to prove the clockwork will not panic
Browse files Browse the repository at this point in the history
  • Loading branch information
ucirello committed Mar 31, 2023
1 parent 703e807 commit 678eccf
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"log"
"math/rand"
"reflect"
"strings"
"sync"
Expand Down Expand Up @@ -880,7 +881,7 @@ func Test_dynamicNesting(t *testing.T) {
for i := 0; i < 10; i++ {
wg.Add(1)
tree.Add(oversight.ChildProcessSpecification{
Name: "child",
Name: fmt.Sprintf("child %d", rand.Int63()),
Restart: oversight.Transient(),
Start: func(ctx context.Context) error {
defer wg.Done()
Expand All @@ -890,13 +891,13 @@ func Test_dynamicNesting(t *testing.T) {
select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(1 * time.Second):
case <-time.After(100 * time.Millisecond):
t.Log("deleting", realChildName)
_ = tree.Delete(realChildName)
return nil
}
},
Shutdown: oversight.Timeout(1 * time.Second),
Shutdown: oversight.Timeout(500 * time.Millisecond),
})
}
return nil
Expand All @@ -907,6 +908,9 @@ func Test_dynamicNesting(t *testing.T) {
if err != nil && err != oversight.ErrNoChildProcessLeft {
t.Fatal("unexpected error:", err)
}
if err := tree.Start(context.Background()); !errors.Is(err, oversight.ErrNoChildProcessLeft) {
t.Fatal("expected error missing: %$v", err)
}
}

func TestTree_shutdownOrder(t *testing.T) {
Expand Down

0 comments on commit 678eccf

Please sign in to comment.