Skip to content

Commit

Permalink
test not timed out on blocking close fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jezek committed Oct 25, 2018
1 parent 240ff30 commit f3d222b
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions xgb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,38 +154,39 @@ func (l leaks) checkTesting(t *testing.T) {
if _, ok := l.goroutines[id]; ok {
continue
}
t.Error(gr.name)
t.Log(gr.name, "\n", string(gr.stack))
}
}

func TestConnOpenClose(t *testing.T) {

t.Logf("creating new dummy blocking server")
//t.Logf("creating new dummy blocking server")
s := newServer()
defer func() {
if err := s.Close(); err != nil {
t.Errorf("server closing error: %v", err)
}
}()
t.Logf("new server created: %v", s)
//t.Logf("new server created: %v", s)

defer leaksMonitor().checkTesting(t)

c, err := postNewConn(&Conn{conn: s})
if err != nil {
t.Fatalf("connect error: %v", err)
}
t.Logf("connection to server created: %v", c)
//t.Logf("connection to server created: %v", c)

closeErr := make(chan error, 1)
closeErr := make(chan struct{})
go func() {
//t.Logf("closing connection to server")
c.Close()
close(closeErr)
}()
closeTimeout := time.Second
select {
case closeErr <- func() error {
t.Logf("closing connection to server")
c.Close()
t.Logf("connection to server closed")
return nil
}():
case <-closeErr:
//t.Logf("connection to server closed")
case <-time.After(closeTimeout):
t.Errorf("*Conn.Close() not responded for %v", closeTimeout)
}
Expand Down

0 comments on commit f3d222b

Please sign in to comment.