-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_test.go
47 lines (40 loc) · 908 Bytes
/
common_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
package percounter
import (
"fmt"
"log"
"math/rand/v2"
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func waitForGcounterValueOf(t *testing.T, expectedValue int64, c ValueSource) {
for w := 0; w < 15; w++ {
if expectedValue == c.Value() {
// all ok
return
}
log.Printf("waiting for the counter to arrive at the expected value of %d ...", expectedValue)
time.Sleep(100 * time.Millisecond)
}
assert.Equal(t, expectedValue, c.Value())
}
func newTempFilename(t *testing.T) string {
f, err := os.CreateTemp(".", "*.gcounter")
if err != nil {
panic(err)
}
fn := f.Name()
_ = f.Close()
t.Cleanup(func() { _ = os.Remove(fn) })
return fn
}
type testGCounterStateSink struct {
lastState GCounterState
}
func (sink *testGCounterStateSink) SetState(s GCounterState) {
sink.lastState = s
}
func randomPort() string {
return fmt.Sprint(5000 + rand.Int32N(2000))
}