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:
James Shubin
2019-03-05 11:32:20 -05:00
parent b1f93b40ae
commit de1691665f
3 changed files with 637 additions and 0 deletions

View File

@@ -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) {