This commit is contained in:
Haley Wang 2024-09-27 13:32:30 +08:00
parent 0eb36e8f2e
commit 319b0fee43
No known key found for this signature in database
GPG key ID: C6299A8A1D6CC50C
2 changed files with 11 additions and 3 deletions

View file

@ -30,7 +30,7 @@ func (as *maxAggrState) pushSamples(samples []pushSample) {
again: again:
v, ok := as.m.Load(outputKey) v, ok := as.m.Load(outputKey)
if !ok { if !ok {
fmt.Printf("wang The entry is missing in the map: %d\n", time.Now().UnixMicro()) // fmt.Printf("wang The entry is missing in the map: %d\n", time.Now().UnixMicro())
// The entry is missing in the map. Try creating it. // The entry is missing in the map. Try creating it.
v = &maxStateValue{ v = &maxStateValue{
max: s.value, max: s.value,
@ -45,7 +45,7 @@ func (as *maxAggrState) pushSamples(samples []pushSample) {
// Use the entry created by a concurrent goroutine. // Use the entry created by a concurrent goroutine.
v = vNew v = vNew
} }
fmt.Printf("wang the right way %d\n", time.Now().Unix()) fmt.Printf("wang This is the right way %d\n", time.Now().Unix())
sv := v.(*maxStateValue) sv := v.(*maxStateValue)
sv.mu.Lock() sv.mu.Lock()
deleted := sv.deleted deleted := sv.deleted

View file

@ -1,7 +1,7 @@
package streamaggr package streamaggr
import ( import (
// "fmt" "fmt"
"testing" "testing"
"time" "time"
@ -87,3 +87,11 @@ func TestPushSampleRace(t *testing.T) {
} }
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
} }
func TestPushSamples(t *testing.T) {
for i := 0; i < 5; i++ {
t.Run(fmt.Sprintf("Run%d", i+1), func(t *testing.T) {
TestPushSampleRace(t)
})
}
}