-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
- Loading branch information
Showing
6 changed files
with
282 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// Copyright (c) The Thanos Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
package query | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/prometheus/prometheus/storage" | ||
) | ||
|
||
func TestAsyncSeriesSet_Next(t *testing.T) { | ||
type fields struct { | ||
ctx context.Context | ||
promise chan storage.SeriesSet | ||
} | ||
|
||
cancelledContext, cancel := context.WithCancel(context.Background()) | ||
cancel() | ||
|
||
closedChannel := make(chan storage.SeriesSet) | ||
close(closedChannel) | ||
|
||
channel := make(chan storage.SeriesSet, 1) | ||
channel <- storage.EmptySeriesSet() | ||
close(channel) | ||
|
||
tests := []struct { | ||
name string | ||
fields fields | ||
want bool | ||
}{ | ||
{ | ||
name: "returns false when context cancelled", | ||
fields: fields{ | ||
ctx: cancelledContext, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "returns false when channel closed", | ||
fields: fields{ | ||
ctx: context.TODO(), | ||
promise: closedChannel, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "proxies call to underlying set", | ||
fields: fields{ | ||
ctx: context.TODO(), | ||
promise: channel, | ||
}, | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
s := &asyncSeriesSet{ | ||
ctx: tt.fields.ctx, | ||
promise: tt.fields.promise, | ||
} | ||
if got := s.Next(); got != tt.want { | ||
t.Errorf("asyncSeriesSet.Next() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestAsyncSeriesSet_Err(t *testing.T) { | ||
type fields struct { | ||
ctx context.Context | ||
promise chan storage.SeriesSet | ||
} | ||
|
||
cancelledContext, cancel := context.WithCancel(context.Background()) | ||
cancel() | ||
|
||
closedChannel := make(chan storage.SeriesSet) | ||
close(closedChannel) | ||
|
||
errRemote := errors.New("remote error") | ||
channel := make(chan storage.SeriesSet, 1) | ||
channel <- errSeriesSet{errRemote} | ||
close(channel) | ||
|
||
tests := []struct { | ||
name string | ||
fields fields | ||
want error | ||
}{ | ||
{ | ||
name: "returns error from context when context cancelled", | ||
fields: fields{ | ||
ctx: cancelledContext, | ||
}, | ||
want: context.Canceled, | ||
}, | ||
{ | ||
name: "returns sentinel error when channel closed", | ||
fields: fields{ | ||
ctx: context.TODO(), | ||
promise: closedChannel, | ||
}, | ||
want: errPrematurelyClosedPromise, | ||
}, | ||
{ | ||
name: "proxies call to underlying set", | ||
fields: fields{ | ||
ctx: context.TODO(), | ||
promise: channel, | ||
}, | ||
want: errRemote, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
s := &asyncSeriesSet{ | ||
ctx: tt.fields.ctx, | ||
promise: tt.fields.promise, | ||
} | ||
for s.Next() { | ||
} | ||
if err := s.Err(); !errors.Is(err, tt.want) { | ||
t.Errorf("asyncSeriesSet.Err() error = %v, want %v", err, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.