498b235461
Build and test / Build and test AMD64 Ubuntu 22.04 (push) Failing after 0s
Publish Builder / amazonlinux2023 (push) Failing after 1s
Build and test / UT for Go (push) Has been skipped
Publish KRTE Images / KRTE (push) Failing after 1s
Build and test / Integration Test (push) Has been skipped
Build and test / Upload Code Coverage (push) Has been skipped
Publish Builder / rockylinux9 (push) Failing after 1s
Publish Builder / ubuntu22.04 (push) Failing after 0s
Publish Builder / ubuntu24.04 (push) Failing after 0s
Publish Gpu Builder / publish-gpu-builder (push) Failing after 1s
Publish Test Images / PyTest (push) Failing after 0s
Build and test / UT for Cpp (push) Has been cancelled
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")
|
|
}
|
|
}
|