lang: funcs: Add live function stream test infrastructure
This adds the ability to test that functions return the expected streams, and to model this behaviour over time. This is done via a "timeline" which runs an ordered list of actions that can both push new values into the function stream, and wait and expect particular outputs. Hopefully this will make our function implementations more robust!
This commit is contained in:
23
util/util.go
23
util/util.go
@@ -19,6 +19,7 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path"
|
||||
"sort"
|
||||
@@ -407,6 +408,28 @@ func TimeAfterOrBlock(t int) <-chan time.Time {
|
||||
return time.After(time.Duration(t) * time.Second)
|
||||
}
|
||||
|
||||
// TimeAfterOrBlockCtx returns a channel that closes after a timeout. If you use
|
||||
// a negative timeout, it will block forever. It can also unblock using context.
|
||||
// Make sure to cancel the context when you're done, or you'll leak a goroutine.
|
||||
func TimeAfterOrBlockCtx(ctx context.Context, t int) <-chan struct{} {
|
||||
ch := make(chan struct{})
|
||||
go func() {
|
||||
defer close(ch)
|
||||
if t < 0 {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
select {
|
||||
case <-time.After(time.Duration(t) * time.Second):
|
||||
case <-ctx.Done():
|
||||
}
|
||||
}()
|
||||
return ch
|
||||
}
|
||||
|
||||
// SystemBusPrivateUsable makes using the private bus usable.
|
||||
// TODO: should be upstream: https://github.com/godbus/dbus/issues/15
|
||||
func SystemBusPrivateUsable() (conn *dbus.Conn, err error) {
|
||||
|
||||
Reference in New Issue
Block a user