2020-10-15 21:31:50 +08:00
|
|
|
package proxy
|
2020-10-15 16:32:22 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-11-14 11:24:49 +08:00
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
2020-11-03 14:53:36 +08:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-10-15 16:32:22 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-11-14 11:24:49 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/allocator"
|
2020-10-15 16:32:22 +08:00
|
|
|
)
|
|
|
|
|
2020-11-14 11:24:49 +08:00
|
|
|
var trueCnt = 0
|
2020-10-15 16:32:22 +08:00
|
|
|
|
2020-11-14 11:24:49 +08:00
|
|
|
func checkFunc(timestamp Timestamp) bool {
|
|
|
|
ret := rand.Intn(2) == 1
|
|
|
|
if ret {
|
|
|
|
trueCnt++
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTimeTick_Start(t *testing.T) {
|
|
|
|
fmt.Println("HHH")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTimeTick_Start2(t *testing.T) {
|
2020-10-15 16:32:22 +08:00
|
|
|
|
2020-11-14 11:24:49 +08:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
|
|
|
|
tsoAllocator, err := allocator.NewTimestampAllocator(ctx)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
err = tsoAllocator.Start()
|
2020-11-03 14:53:36 +08:00
|
|
|
assert.Nil(t, err)
|
2020-10-15 16:32:22 +08:00
|
|
|
|
2020-11-14 11:24:49 +08:00
|
|
|
tt := newTimeTick(ctx, tsoAllocator, checkFunc)
|
2020-10-15 16:32:22 +08:00
|
|
|
|
2020-11-14 11:24:49 +08:00
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
tsoAllocator.Close()
|
|
|
|
tt.Close()
|
|
|
|
}()
|
2020-10-15 16:32:22 +08:00
|
|
|
|
2020-11-14 11:24:49 +08:00
|
|
|
tt.Start()
|
2020-11-12 12:04:12 +08:00
|
|
|
|
2020-11-14 11:24:49 +08:00
|
|
|
<-ctx.Done()
|
2020-10-15 16:32:22 +08:00
|
|
|
|
|
|
|
}
|