MCPcopy
hub / github.com/gliderlabs/ssh / TestServerClose

Function TestServerClose

server_test.go:82–126  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

80}
81
82func TestServerClose(t *testing.T) {
83 l := newLocalListener()
84 s := &Server{
85 Handler: func(s Session) {
86 time.Sleep(5 * time.Second)
87 },
88 }
89 go func() {
90 err := s.Serve(l)
91 if err != nil && err != ErrServerClosed {
92 t.Fatal(err)
93 }
94 }()
95
96 clientDoneChan := make(chan struct{})
97 closeDoneChan := make(chan struct{})
98
99 sess, _, cleanup := newClientSession(t, l.Addr().String(), nil)
100 go func() {
101 defer cleanup()
102 defer close(clientDoneChan)
103 <-closeDoneChan
104 if err := sess.Run(""); err != nil && err != io.EOF {
105 t.Fatal(err)
106 }
107 }()
108
109 go func() {
110 err := s.Close()
111 if err != nil {
112 t.Fatal(err)
113 }
114 close(closeDoneChan)
115 }()
116
117 timeout := time.After(100 * time.Millisecond)
118 select {
119 case <-timeout:
120 t.Error("timeout")
121 return
122 case <-s.getDoneChan():
123 <-clientDoneChan
124 return
125 }
126}

Callers

nothing calls this directly

Calls 5

ServeMethod · 0.95
CloseMethod · 0.95
getDoneChanMethod · 0.95
newLocalListenerFunction · 0.85
newClientSessionFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…