test(config): accept intermediate reloads in TestWatch's burst
On a loaded runner the watcher can reload the truncated file between two writes of the burst. Only the same config sent twice in a row is a duplicate reload.
- commit
- b5f665e501972165a8cdc607e8f81ede1fd2f77b
- author
- brice · · 2026-10-08 08:42 UTC
- committer
- brice · · 2026-10-08 09:59 UTC
- parent
- 7ad9c3b
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +14 -4
M internal/adapters/config/watch_test.go +14 -4
| @@ -81,10 +81,20 @@ func TestWatch(t *testing.T) { | |||
| 81 | 81 | time.Sleep(15 * time.Millisecond) | |
| 82 | 82 | } | |
| 83 | 83 | receive("#00ff00") | |
| 84 | - | select { | |
| 85 | - | case <-out: | |
| 86 | - | t.Fatal("duplicate reload") | |
| 87 | - | case <-time.After(250 * time.Millisecond): | |
| 84 | + | // A loaded machine may pause past the debounce inside the burst | |
| 85 | + | // and reload the truncated file in between: that is a change, not a | |
| 86 | + | // duplicate. Only the same config sent twice in a row is one. | |
| 87 | + | prev := "#00ff00" | |
| 88 | + | for quiet := false; !quiet; { | |
| 89 | + | select { | |
| 90 | + | case c := <-out: | |
| 91 | + | if c.Config.Background.Color == prev { | |
| 92 | + | t.Fatal("duplicate reload") | |
| 93 | + | } | |
| 94 | + | prev = c.Config.Background.Color | |
| 95 | + | case <-time.After(250 * time.Millisecond): | |
| 96 | + | quiet = true | |
| 97 | + | } | |
| 88 | 98 | } | |
| 89 | 99 | // An invalid value keeps the default for that key; other keys still apply. | |
| 90 | 100 | write(path, "background = bad\nborder.width = 5\n") | |
| @@ -81,10 +81,20 @@ func TestWatch(t *testing.T) { | |||||
| 81 | time.Sleep(15 * time.Millisecond) | 81 | time.Sleep(15 * time.Millisecond) | ||
| 82 | } | 82 | } | ||
| 83 | receive("#00ff00") | 83 | receive("#00ff00") | ||
| 84 | - | select { | 84 | + | // A loaded machine may pause past the debounce inside the burst |
| 85 | - | case <-out: | 85 | + | // and reload the truncated file in between: that is a change, not a |
| 86 | - | t.Fatal("duplicate reload") | 86 | + | // duplicate. Only the same config sent twice in a row is one. |
| 87 | - | case <-time.After(250 * time.Millisecond): | 87 | + | prev := "#00ff00" |
| 88 | + | for quiet := false; !quiet; { | |||
| 89 | + | select { | |||
| 90 | + | case c := <-out: | |||
| 91 | + | if c.Config.Background.Color == prev { | |||
| 92 | + | t.Fatal("duplicate reload") | |||
| 93 | + | } | |||
| 94 | + | prev = c.Config.Background.Color | |||
| 95 | + | case <-time.After(250 * time.Millisecond): | |||
| 96 | + | quiet = true | |||
| 97 | + | } | |||
| 88 | } | 98 | } | ||
| 89 | // An invalid value keeps the default for that key; other keys still apply. | 99 | // An invalid value keeps the default for that key; other keys still apply. | ||
| 90 | write(path, "background = bad\nborder.width = 5\n") | 100 | write(path, "background = bad\nborder.width = 5\n") | ||