(t *testing.T)
| 91 | } |
| 92 | |
| 93 | func TestFailedChannelSend(t *testing.T) { |
| 94 | s := RunDefaultServer() |
| 95 | defer s.Shutdown() |
| 96 | |
| 97 | ec := NewEConn(t) |
| 98 | defer ec.Close() |
| 99 | |
| 100 | nc := ec.Conn |
| 101 | ch := make(chan bool) |
| 102 | wch := make(chan bool) |
| 103 | |
| 104 | nc.Opts.AsyncErrorCB = func(c *nats.Conn, s *nats.Subscription, e error) { |
| 105 | wch <- true |
| 106 | } |
| 107 | |
| 108 | if err := ec.BindSendChan("foo", ch); err != nil { |
| 109 | t.Fatalf("Failed to bind to a receive channel: %v\n", err) |
| 110 | } |
| 111 | |
| 112 | nc.Flush() |
| 113 | |
| 114 | go func() { |
| 115 | time.Sleep(100 * time.Millisecond) |
| 116 | nc.Close() |
| 117 | }() |
| 118 | |
| 119 | func() { |
| 120 | for { |
| 121 | select { |
| 122 | case ch <- true: |
| 123 | case <-wch: |
| 124 | return |
| 125 | case <-time.After(time.Second): |
| 126 | t.Fatal("Failed to get async error cb") |
| 127 | } |
| 128 | } |
| 129 | }() |
| 130 | |
| 131 | ec = NewEConn(t) |
| 132 | defer ec.Close() |
| 133 | |
| 134 | nc = ec.Conn |
| 135 | bch := make(chan []byte) |
| 136 | |
| 137 | nc.Opts.AsyncErrorCB = func(c *nats.Conn, s *nats.Subscription, e error) { |
| 138 | wch <- true |
| 139 | } |
| 140 | |
| 141 | if err := ec.BindSendChan("foo", bch); err != nil { |
| 142 | t.Fatalf("Failed to bind to a receive channel: %v\n", err) |
| 143 | } |
| 144 | |
| 145 | buf := make([]byte, 2*1024*1024) |
| 146 | bch <- buf |
| 147 | |
| 148 | if e := Wait(wch); e != nil { |
| 149 | t.Fatal("Failed to call async err handler") |
| 150 | } |
nothing calls this directly
no test coverage detected