-
Notifications
You must be signed in to change notification settings - Fork 458
/
frontend_processor_test.go
80 lines (63 loc) · 2.19 KB
/
frontend_processor_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// SPDX-License-Identifier: AGPL-3.0-only
// Provenance-includes-location: https://github.com/cortexproject/cortex/blob/master/pkg/querier/worker/frontend_processor_test.go
// Provenance-includes-license: Apache-2.0
// Provenance-includes-copyright: The Cortex Authors.
package worker
import (
"context"
"testing"
"time"
"github.com/go-kit/log"
"github.com/grafana/dskit/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/atomic"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
func TestRecvFailDoesntCancelProcess(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// We use random port here, hopefully without any gRPC server.
cc, err := grpc.DialContext(ctx, "localhost:999", grpc.WithTransportCredentials(insecure.NewCredentials()))
require.NoError(t, err)
cfg := Config{}
mgr := newFrontendProcessor(cfg, nil, log.NewNopLogger())
running := atomic.NewBool(false)
go func() {
running.Store(true)
defer running.Store(false)
mgr.processQueriesOnSingleStream(ctx, cc, "test:12345")
}()
test.Poll(t, time.Second, true, func() interface{} {
return running.Load()
})
// Wait a bit, and verify that processQueriesOnSingleStream is still running, and hasn't stopped
// just because it cannot contact frontend.
time.Sleep(100 * time.Millisecond)
assert.Equal(t, true, running.Load())
cancel()
test.Poll(t, time.Second, false, func() interface{} {
return running.Load()
})
}
func TestContextCancelStopsProcess(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// We use random port here, hopefully without any gRPC server.
cc, err := grpc.DialContext(ctx, "localhost:999", grpc.WithTransportCredentials(insecure.NewCredentials()))
require.NoError(t, err)
pm := newProcessorManager(ctx, &mockProcessor{}, cc, "test")
pm.concurrency(1)
test.Poll(t, time.Second, 1, func() interface{} {
return int(pm.currentProcessors.Load())
})
cancel()
test.Poll(t, time.Second, 0, func() interface{} {
return int(pm.currentProcessors.Load())
})
pm.stop()
test.Poll(t, time.Second, 0, func() interface{} {
return int(pm.currentProcessors.Load())
})
}