A watch asked before Serve is refused, which would have left every build module on its settings file again. stdio.Served closes when Serve has the channel; WatchConfigServed waits on it, and Pull starts the watch beside its loop.
28 lines
658 B
Go
28 lines
658 B
Go
package stdio
|
|
|
|
import (
|
|
"io"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// 1887/AC-wake: code started before Serve (a build puller's watch of its capacity) waits on Served, which closes once
|
|
// Serve has the runtime's channel, so it asks the runtime then and not before.
|
|
func TestServedClosesOnceServing(t *testing.T) {
|
|
served, servedOnce = make(chan struct{}), sync.Once{}
|
|
select {
|
|
case <-Served():
|
|
t.Fatal("Served closed before Serve")
|
|
default:
|
|
}
|
|
inR, inW := io.Pipe()
|
|
defer inW.Close()
|
|
go func() { _ = ServeOn("", nil, inR, io.Discard) }()
|
|
select {
|
|
case <-Served():
|
|
case <-time.After(2 * time.Second):
|
|
t.Fatal("Served did not close once serving")
|
|
}
|
|
}
|