Merge pull request 'test: fix two flaky tests seen in CI' (#19) from fix/flaky-tests into main
Reviewed-on: https://git.bnema.dev/bnema/neferwl/pulls/19
2 files · +18 -5
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") | ||
M internal/adapters/wayland/activation_test.go +4 -1
| @@ -163,8 +163,11 @@ func TestActivationPressSerial(t *testing.T) { | |||
| 163 | 163 | token = newToken(t, c, manager, serial+100, seat) | |
| 164 | 164 | requestProtocol(t, c, manager, xdgactivation.ActivationV1RequestActivate, token, surf) | |
| 165 | 165 | noActivation(t, c, events) | |
| 166 | - | // The focus moved after the press: stale. | |
| 166 | + | // The focus moved after the press: stale. Wait for each step: the | |
| 167 | + | // focus starts at 0, so a single wait could pass before either | |
| 168 | + | // command applies and leave the client focused. | |
| 167 | 169 | commands <- ports.FocusWindow{ID: w.ID} | |
| 170 | + | waitFocus(t, s, w.ID) | |
| 168 | 171 | commands <- ports.FocusWindow{} | |
| 169 | 172 | waitFocus(t, s, 0) | |
| 170 | 173 | token = newToken(t, c, manager, serial, seat) | |
| @@ -163,8 +163,11 @@ func TestActivationPressSerial(t *testing.T) { | |||||
| 163 | token = newToken(t, c, manager, serial+100, seat) | 163 | token = newToken(t, c, manager, serial+100, seat) | ||
| 164 | requestProtocol(t, c, manager, xdgactivation.ActivationV1RequestActivate, token, surf) | 164 | requestProtocol(t, c, manager, xdgactivation.ActivationV1RequestActivate, token, surf) | ||
| 165 | noActivation(t, c, events) | 165 | noActivation(t, c, events) | ||
| 166 | - | // The focus moved after the press: stale. | 166 | + | // The focus moved after the press: stale. Wait for each step: the |
| 167 | + | // focus starts at 0, so a single wait could pass before either | |||
| 168 | + | // command applies and leave the client focused. | |||
| 167 | commands <- ports.FocusWindow{ID: w.ID} | 169 | commands <- ports.FocusWindow{ID: w.ID} | ||
| 170 | + | waitFocus(t, s, w.ID) | |||
| 168 | commands <- ports.FocusWindow{} | 171 | commands <- ports.FocusWindow{} | ||
| 169 | waitFocus(t, s, 0) | 172 | waitFocus(t, s, 0) | ||
| 170 | token = newToken(t, c, manager, serial, seat) | 173 | token = newToken(t, c, manager, serial, seat) | ||