The credential wait's test stays under a second, and a failed watch says the re-read, not a restart (issue 1496)
Review of 3baeaec: TestAwaitCredential took 1.9 s, over the unit limit; it now
sets the watch's settle to 10 ms, writes at 20 ms and gives up at 100 ms (0.2 s).
The watch's journal line for a failure named a bundle and a restart; the
credential wait now says it is read again every 30 s instead.
This commit is contained in:
@@ -171,7 +171,8 @@ func awaitCredential(file string, until time.Time, say func(string, ...any)) (bu
|
||||
case changed <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
}, func(format string, args ...any) { say(format, args...) })
|
||||
}, func(format string, args ...any) { say(format, args...) },
|
||||
fmt.Sprintf("the credential is read again every %s instead", rereadEvery))
|
||||
if werr != nil {
|
||||
say("cannot watch %s (%v): it is read again every %s instead", file, werr, rereadEvery)
|
||||
} else {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/novox/mesh-tools/node-tools/internal/bus"
|
||||
"github.com/novox/mesh-tools/node-tools/internal/runtime"
|
||||
)
|
||||
|
||||
// A runtime started before its credential is on the machine waits for it, woken by the watch of its directory, and gives
|
||||
@@ -18,7 +19,9 @@ import (
|
||||
func TestAwaitCredential(t *testing.T) {
|
||||
const good = `{"url":"tls://bus.example:4222","module":"m"}`
|
||||
rereadEvery = time.Hour // only the watch can wake the read in time
|
||||
t.Cleanup(func() { rereadEvery = 30 * time.Second })
|
||||
settle := runtime.Settle
|
||||
runtime.Settle = 10 * time.Millisecond // a unit test stays well under a second
|
||||
t.Cleanup(func() { rereadEvery, runtime.Settle = 30*time.Second, settle })
|
||||
place := func(path, body string) {
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -34,7 +37,7 @@ func TestAwaitCredential(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
before string // written before the wait, "" none
|
||||
later string // written 200ms into the wait, "" none
|
||||
later string // written 20ms into the wait, "" none
|
||||
deeper bool // the file's directory is not there at the start
|
||||
bound time.Duration
|
||||
want string // "" a credential; else a word of the error
|
||||
@@ -44,7 +47,7 @@ func TestAwaitCredential(t *testing.T) {
|
||||
{name: "written during the wait", later: good, bound: 5 * time.Second, said: 2},
|
||||
{name: "empty, then filled", before: " ", later: good, bound: 5 * time.Second, said: 2},
|
||||
{name: "its directory made during the wait", later: good, deeper: true, bound: 5 * time.Second, said: 2},
|
||||
{name: "never written", bound: 400 * time.Millisecond, want: "waited", said: 1},
|
||||
{name: "never written", bound: 100 * time.Millisecond, want: "waited", said: 1},
|
||||
{name: "no url", before: `{"module":"m"}`, bound: 5 * time.Second, want: "not a broker credential", said: 0},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
@@ -57,7 +60,7 @@ func TestAwaitCredential(t *testing.T) {
|
||||
place(file, c.before)
|
||||
}
|
||||
if c.later != "" {
|
||||
go func() { time.Sleep(200 * time.Millisecond); place(file, c.later) }()
|
||||
go func() { time.Sleep(20 * time.Millisecond); place(file, c.later) }()
|
||||
}
|
||||
var said []string
|
||||
began := time.Now()
|
||||
|
||||
Reference in New Issue
Block a user