distribution: a step given up at its bound is said given up, and its call's end is said later
Builds: design 47 G A-443, A-443a
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -19,6 +21,36 @@ func TestAHungStepAnswersWithItsName(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A step given up on is said given up by name, and the log says later when the call behind it ended and how (A-443a).
|
||||
func TestAGivenUpStepSaysWhenItsCallEnded(t *testing.T) {
|
||||
var mu sync.Mutex
|
||||
var lines []string
|
||||
ended := make(chan struct{})
|
||||
w := func(f string, a ...any) {
|
||||
l := fmt.Sprintf(f, a...)
|
||||
mu.Lock()
|
||||
lines = append(lines, l)
|
||||
mu.Unlock()
|
||||
if strings.Contains(l, "the put of a chunk") && strings.Contains(l, "its call ended after") {
|
||||
close(ended)
|
||||
}
|
||||
}
|
||||
old := logTo.Swap(&w)
|
||||
defer logTo.Store(old)
|
||||
release := make(chan struct{})
|
||||
if _, err := step(10*time.Millisecond, "the put of a chunk", func() (int, error) { <-release; return 0, fmt.Errorf("bus closed") }); err == nil {
|
||||
t.Fatal("not given up")
|
||||
}
|
||||
close(release)
|
||||
<-ended
|
||||
mu.Lock()
|
||||
all := strings.Join(lines, "\n")
|
||||
mu.Unlock()
|
||||
if !strings.Contains(all, "given up") || !strings.Contains(all, "bus closed") {
|
||||
t.Fatalf("log: %s", all)
|
||||
}
|
||||
}
|
||||
|
||||
// The finding is said off the caller's path: a writer that never answers does not hold the call that says it.
|
||||
func TestAFindingIsSaidOffThePath(t *testing.T) {
|
||||
block := make(chan struct{})
|
||||
|
||||
Reference in New Issue
Block a user