Skip to content

Commit

Permalink
TestObjectSignalHandling: minor refactor
Browse files Browse the repository at this point in the history
 - embed fetchSignal into checkSignal;
 - remove t and timeout arguments;
 - add t.Helper so that errors show correct line number;

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Feb 15, 2022
1 parent 81ff899 commit 2c3cf65
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,6 @@ func (_ nopServer) Nop() *Error {
return nil
}

func fetchSignal(t *testing.T, ch chan *Signal, timeout time.Duration) *Signal {
select {
case sig := <-ch:
return sig
case <-time.After(timeout):
t.Fatalf("Failed to fetch signal in specified timeout %s", timeout)
}
return nil
}

func TestObjectSignalHandling(t *testing.T) {
bus, err := ConnectSessionBus()
if err != nil {
Expand Down Expand Up @@ -133,7 +123,19 @@ func TestObjectSignalHandling(t *testing.T) {
emit(path, iface+".Heartbeat", uint32(6))
}()

checkSignal := func(sig *Signal, value uint32) {
checkSignal := func(ch chan *Signal, value uint32) {
t.Helper()

const timeout = 50 * time.Millisecond
var sig *Signal

select {
case sig = <-ch:
// do nothing
case <-time.After(timeout):
t.Fatalf("Failed to fetch signal in specified timeout %s", timeout)
}

if sig.Path != path {
t.Errorf("signal.Path mismatch: %s != %s", path, sig.Path)
}
Expand All @@ -153,9 +155,9 @@ func TestObjectSignalHandling(t *testing.T) {
}
}

checkSignal(fetchSignal(t, ch, 50*time.Millisecond), 1)
checkSignal(fetchSignal(t, ch, 50*time.Millisecond), 2)
checkSignal(fetchSignal(t, ch, 50*time.Millisecond), 5)
checkSignal(ch, 1)
checkSignal(ch, 2)
checkSignal(ch, 5)

obj.RemoveMatchSignal(iface, "Heartbeat", WithMatchObjectPath(obj.Path()))
select {
Expand Down

0 comments on commit 2c3cf65

Please sign in to comment.