109 lines
3.1 KiB
Go
109 lines
3.1 KiB
Go
//go:build integration
|
|
|
|
package main
|
|
|
|
// Issue 1165: these tests make a real unix socket and watch its directory, so they run in the integration level.
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// Issue 1165: a file whose write failed because the node-engine's socket was gone is written when the socket is made
|
|
// again, with no timer; a file that was placed is not asked again by it.
|
|
func TestNatsAFillThatFailedForWantOfTheSocketIsTriedWhenTheSocketReturns(t *testing.T) {
|
|
b := startBus(t)
|
|
heard := b.listen(t)
|
|
e := newEngine(t, map[string]string{dunstrc: "owned"})
|
|
b.config(t, "dunst", "font-size", "13")
|
|
b.assign(t, "dunst", dunst(t))
|
|
aClient(t, b, e, t.TempDir())
|
|
|
|
eventually(t, "the failure is said", func() bool {
|
|
r, _ := heard.last("dunst")
|
|
return r.Status == StatusFailed && strings.Contains(r.Reason, "fill.sock")
|
|
})
|
|
if got := e.read(t, dunstrc); got != "" {
|
|
t.Fatalf("written without a socket: %q", got)
|
|
}
|
|
e.listen(t)
|
|
eventually(t, "dunstrc is written once the socket is back", func() bool {
|
|
return strings.Contains(e.read(t, dunstrc), "Monospace 13")
|
|
})
|
|
eventually(t, "and the report says applied", func() bool {
|
|
r, _ := heard.last("dunst")
|
|
return r.Status == StatusApplied
|
|
})
|
|
}
|
|
|
|
func TestNatsAReturningSocketAsksNothingOfAModuleThatWasPlaced(t *testing.T) {
|
|
b := startBus(t)
|
|
e := newEngine(t, map[string]string{dunstrc: "owned"})
|
|
stop := e.listen(t)
|
|
b.config(t, "dunst", "font-size", "13")
|
|
b.assign(t, "dunst", dunst(t))
|
|
aClient(t, b, e, t.TempDir())
|
|
eventually(t, "dunstrc is filled", func() bool { return strings.Contains(e.read(t, dunstrc), "Monospace 13") })
|
|
_, before := e.counts(dunstrc)
|
|
|
|
// The node-engine replaces itself: the socket goes and returns, and a later change proves the loop ran past it.
|
|
stop()
|
|
e.listen(t)
|
|
b.config(t, "dunst", "font-size", "15")
|
|
eventually(t, "the change is written", func() bool { return strings.Contains(e.read(t, dunstrc), "Monospace 15") })
|
|
_, after := e.counts(dunstrc)
|
|
if after-before != 1 {
|
|
t.Errorf("dunstrc was asked %d times for one change", after-before)
|
|
}
|
|
}
|
|
|
|
func TestWatchSocketWakesWhenTheSocketIsMadeAndWhenItsDirectoryReturns(t *testing.T) {
|
|
base, err := os.MkdirTemp("/tmp", "ws-")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { os.RemoveAll(base) })
|
|
dir := filepath.Join(base, "engine")
|
|
if err := os.Mkdir(dir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
socket := filepath.Join(dir, "fill.sock")
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
up, err := watchSocket(ctx, socket)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
heard := func(what string) {
|
|
t.Helper()
|
|
select {
|
|
case <-up:
|
|
case <-time.After(5 * time.Second):
|
|
t.Fatalf("no wake for %s", what)
|
|
}
|
|
}
|
|
l, err := net.Listen("unix", socket)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
heard("the socket made")
|
|
l.Close()
|
|
// The whole directory goes, as with a runtime directory removed on stop, and returns with the socket.
|
|
if err := os.RemoveAll(dir); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.Mkdir(dir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if l, err = net.Listen("unix", socket); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer l.Close()
|
|
heard("the directory and socket back")
|
|
}
|