internal/uevent: integrate error handling in event loop
All checks were successful
Test / Create distribution (push) Successful in 1m17s
Test / Sandbox (push) Successful in 3m13s
Test / Hakurei (push) Successful in 4m18s
Test / ShareFS (push) Successful in 4m24s
Test / Sandbox (race detector) (push) Successful in 5m35s
Test / Hakurei (race detector) (push) Successful in 6m42s
Test / Flake checks (push) Successful in 1m25s
All checks were successful
Test / Create distribution (push) Successful in 1m17s
Test / Sandbox (push) Successful in 3m13s
Test / Hakurei (push) Successful in 4m18s
Test / ShareFS (push) Successful in 4m24s
Test / Sandbox (race detector) (push) Successful in 5m35s
Test / Hakurei (race detector) (push) Successful in 6m42s
Test / Flake checks (push) Successful in 1m25s
There are many subtleties when recovering from errors in the event loop, and coldboot requires internals to drain the receive buffer as synthetic uevents are being arranged. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"hakurei.app/fhs"
|
||||
"hakurei.app/internal/uevent"
|
||||
)
|
||||
|
||||
@@ -155,13 +156,23 @@ func TestDialConsume(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
|
||||
consume := func(c *uevent.Conn, ctx context.Context) error {
|
||||
return c.Consume(ctx, fhs.Sys, events, false, func(path string) {
|
||||
t.Log("coldboot visited", path)
|
||||
}, func(err error) bool {
|
||||
t.Log(err)
|
||||
_, ok := err.(uevent.NeedsColdboot)
|
||||
return !ok
|
||||
}, nil)
|
||||
}
|
||||
|
||||
wg.Go(func() {
|
||||
if err = c.Consume(ctx, events); err != context.Canceled {
|
||||
if err = consume(c, ctx); err != context.Canceled {
|
||||
panic(err)
|
||||
}
|
||||
})
|
||||
wg.Go(func() {
|
||||
if err0 = c0.Consume(ctx, events); err0 != context.Canceled {
|
||||
if err0 = consume(c0, ctx); err0 != context.Canceled {
|
||||
panic(err0)
|
||||
}
|
||||
})
|
||||
@@ -185,11 +196,11 @@ func TestDialConsume(t *testing.T) {
|
||||
exclExit := make(chan struct{})
|
||||
wg.Go(func() {
|
||||
defer func() { exclExit <- struct{}{} }()
|
||||
errs[0] = c.Consume(ctx, events)
|
||||
errs[0] = consume(c, ctx)
|
||||
})
|
||||
wg.Go(func() {
|
||||
defer func() { exclExit <- struct{}{} }()
|
||||
errs[1] = c.Consume(ctx, events)
|
||||
errs[1] = consume(c, ctx)
|
||||
})
|
||||
<-exclExit
|
||||
cancel()
|
||||
|
||||
Reference in New Issue
Block a user