Skip to content

Commit

Permalink
test(share/utils): fix no deadline test for ctxWithSplitTimeout (#2502)
Browse files Browse the repository at this point in the history

Quick fix for one of the ctxWithSplitTimeout test cases.
  • Loading branch information
walldiss authored Jul 26, 2023
1 parent 6a7275d commit 7d981d5
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions share/getters/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func Test_ctxWithSplitTimeout(t *testing.T) {
splitFactor: []int{-1, 0, 1, 2},
minTimeout: time.Minute,
},
want: 0,
want: time.Minute,
},
{
name: "no context timeout, minTimeout = 0",
Expand All @@ -201,12 +201,18 @@ func Test_ctxWithSplitTimeout(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
for _, sf := range tt.args.splitFactor {
ctx, cancel := context.WithTimeout(context.Background(), tt.args.ctxTimeout)
ctx, cancel := context.WithCancel(context.Background())
// add timeout if original context should have it
if tt.args.ctxTimeout > 0 {
ctx, cancel = context.WithTimeout(ctx, tt.args.ctxTimeout)
}
t.Cleanup(cancel)
got, _ := ctxWithSplitTimeout(ctx, sf, tt.args.minTimeout)
dl, ok := got.Deadline()
if !ok {
require.Equal(t, tt.want, 0)
// in case no deadline is found in ctx or not expected to be found, check both cases apply at the same time
if !ok || tt.want == 0 {
require.False(t, ok)
require.Equal(t, tt.want, time.Duration(0))
continue
}
d := time.Until(dl)
Expand Down

0 comments on commit 7d981d5

Please sign in to comment.