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

Function TestServerShutdown

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

Source from the content-addressed store, hash-verified

29}
30
31func TestServerShutdown(t *testing.T) {
32 l := newLocalListener()
33 testBytes := []byte("Hello world\n")
34 s := &Server{
35 Handler: func(s Session) {
36 s.Write(testBytes)
37 time.Sleep(50 * time.Millisecond)
38 },
39 }
40 go func() {
41 err := s.Serve(l)
42 if err != nil && err != ErrServerClosed {
43 t.Fatal(err)
44 }
45 }()
46 sessDone := make(chan struct{})
47 sess, _, cleanup := newClientSession(t, l.Addr().String(), nil)
48 go func() {
49 defer cleanup()
50 defer close(sessDone)
51 var stdout bytes.Buffer
52 sess.Stdout = &stdout
53 if err := sess.Run(""); err != nil {
54 t.Fatal(err)
55 }
56 if !bytes.Equal(stdout.Bytes(), testBytes) {
57 t.Fatalf("expected = %s; got %s", testBytes, stdout.Bytes())
58 }
59 }()
60
61 srvDone := make(chan struct{})
62 go func() {
63 defer close(srvDone)
64 err := s.Shutdown(context.Background())
65 if err != nil {
66 t.Fatal(err)
67 }
68 }()
69
70 timeout := time.After(2 * time.Second)
71 select {
72 case <-timeout:
73 t.Fatal("timeout")
74 return
75 case <-srvDone:
76 // TODO: add timeout for sessDone
77 <-sessDone
78 return
79 }
80}
81
82func TestServerClose(t *testing.T) {
83 l := newLocalListener()

Callers

nothing calls this directly

Calls 5

ServeMethod · 0.95
ShutdownMethod · 0.95
newLocalListenerFunction · 0.85
newClientSessionFunction · 0.85
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…