forked from FeatureBaseDB/featurebase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracker_test.go
69 lines (60 loc) · 2.09 KB
/
tracker_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
// Copyright 2022 Molecula Corp. (DBA FeatureBase).
// SPDX-License-Identifier: Apache-2.0
package pilosa
import (
"fmt"
"testing"
"time"
)
func TestRingBuffer(t *testing.T) {
tests := []struct {
start int
count int
queries []string
}{
{start: 0, count: 0, queries: []string{}},
{start: 0, count: 1, queries: []string{"0"}},
{start: 0, count: 2, queries: []string{"0", "1"}},
{start: 0, count: 3, queries: []string{"0", "1", "2"}},
{start: 0, count: 4, queries: []string{"0", "1", "2", "3"}},
{start: 0, count: 5, queries: []string{"0", "1", "2", "3", "4"}},
{start: 1, count: 5, queries: []string{"1", "2", "3", "4", "5"}},
{start: 2, count: 5, queries: []string{"2", "3", "4", "5", "6"}},
{start: 3, count: 5, queries: []string{"3", "4", "5", "6", "7"}},
{start: 4, count: 5, queries: []string{"4", "5", "6", "7", "8"}},
{start: 0, count: 5, queries: []string{"5", "6", "7", "8", "9"}},
{start: 1, count: 5, queries: []string{"6", "7", "8", "9", "10"}},
{start: 2, count: 5, queries: []string{"7", "8", "9", "10", "11"}},
}
buffer := newRingBuffer(5)
for k := 0; k < len(tests); k++ {
if !(buffer.start == tests[k].start && buffer.count == tests[k].count) {
t.Fatalf("expected %d %d, found %d %d", tests[k].start, tests[k].count, buffer.start, buffer.count)
}
for n, q := range buffer.slice() {
if q.PQL != tests[k].queries[n] {
t.Fatalf("test[%d], buffer[%d] expected querystring '%s', found '%s'", k, n, tests[k].queries[n], q.PQL)
}
}
buffer.add(pastQuery{PQL: fmt.Sprintf("%d", k)})
}
}
func TestQueryTracker(t *testing.T) {
tracker := newQueryTracker(5)
defer tracker.Stop()
if queries := tracker.ActiveQueries(); len(queries) > 0 {
t.Fatalf("expected no active queries; found %v", queries)
}
qs := tracker.Start("test query", "test SQL", "node0", "i", time.Now())
var queries []ActiveQueryStatus
for len(queries) < 1 {
queries = tracker.ActiveQueries()
}
if len(queries) > 1 || queries[0].PQL != "test query" {
t.Fatalf("unexpected queries: %v", queries)
}
tracker.Finish(qs)
for len(queries) > 0 {
queries = tracker.ActiveQueries()
}
}