Skip to content

Commit 62007dc

Browse files
test to cover deadlock condition
1 parent dd7bb9c commit 62007dc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

qemu/domain_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,28 @@ func TestEvents(t *testing.T) {
577577
}
578578
}
579579

580+
// Test when a listener connects, but disconnects without
581+
// receiving from the events chaannel returned.
582+
func TestEventsDerelictListener(t *testing.T) {
583+
d, done := testDomain(t, nil)
584+
defer done()
585+
586+
_, stop, err := d.Events()
587+
if err != nil {
588+
t.Error(err)
589+
}
590+
591+
<-time.After(200 * time.Millisecond)
592+
593+
stop <- struct{}{}
594+
select {
595+
case <-stop:
596+
return
597+
case <-time.After(time.Millisecond * 20):
598+
t.Error("shutdown failed to complete")
599+
}
600+
}
601+
580602
func TestEventsUnsupported(t *testing.T) {
581603
d, done := testDomain(t, nil)
582604
defer done()
@@ -589,6 +611,8 @@ func TestEventsUnsupported(t *testing.T) {
589611
}
590612

591613
func testDomain(t *testing.T, fn func(qmp.Command) (interface{}, error)) (*Domain, func()) {
614+
t.Helper()
615+
592616
mon := &testMonitor{fn: fn}
593617
d, err := NewDomain(mon, "test")
594618
if err != nil {

0 commit comments

Comments
 (0)