mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-02 03:48:37 +08:00
3563136c2a
issue: #33285 - optimize the message package - add interceptor package to achieve append operation intercepting. - add timetick interceptor to attach timetick properties for message. - add timetick background task to send timetick message. Signed-off-by: chyezh <chyezh@outlook.com>
52 lines
883 B
Go
52 lines
883 B
Go
package syncutil
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestFuture_SetAndGet(t *testing.T) {
|
|
f := NewFuture[int]()
|
|
go func() {
|
|
time.Sleep(1 * time.Second) // Simulate some work
|
|
f.Set(42)
|
|
}()
|
|
|
|
val := f.Get()
|
|
if val != 42 {
|
|
t.Errorf("Expected value 42, got %d", val)
|
|
}
|
|
}
|
|
|
|
func TestFuture_Done(t *testing.T) {
|
|
f := NewFuture[string]()
|
|
go func() {
|
|
f.Set("done")
|
|
}()
|
|
|
|
select {
|
|
case <-f.Done():
|
|
// Success
|
|
case <-time.After(20 * time.Millisecond):
|
|
t.Error("Expected future to be done within 2 seconds")
|
|
}
|
|
}
|
|
|
|
func TestFuture_Ready(t *testing.T) {
|
|
f := NewFuture[float64]()
|
|
go func() {
|
|
time.Sleep(20 * time.Millisecond) // Simulate some work
|
|
f.Set(3.14)
|
|
}()
|
|
|
|
if f.Ready() {
|
|
t.Error("Expected future not to be ready immediately")
|
|
}
|
|
|
|
<-f.Done() // Wait for the future to be set
|
|
|
|
if !f.Ready() {
|
|
t.Error("Expected future to be ready after being set")
|
|
}
|
|
}
|