TestCleanCancel tests passed context is cancelled at start. No packet should be sent. Connection should keep current status.
(t *testing.T)
| 115 | // TestCleanCancel tests passed context is cancelled at start. |
| 116 | // No packet should be sent. Connection should keep current status. |
| 117 | func TestCleanCancel(t *testing.T) { |
| 118 | mc := &mysqlConn{ |
| 119 | closech: make(chan struct{}), |
| 120 | } |
| 121 | mc.startWatcher() |
| 122 | defer mc.cleanup() |
| 123 | |
| 124 | ctx, cancel := context.WithCancel(context.Background()) |
| 125 | cancel() |
| 126 | |
| 127 | for range 3 { // Repeat same behavior |
| 128 | err := mc.Ping(ctx) |
| 129 | if err != context.Canceled { |
| 130 | t.Errorf("expected context.Canceled, got %#v", err) |
| 131 | } |
| 132 | |
| 133 | if mc.closed.Load() { |
| 134 | t.Error("expected mc is not closed, closed actually") |
| 135 | } |
| 136 | |
| 137 | if mc.watching { |
| 138 | t.Error("expected watching is false, but true") |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | func TestPingMarkBadConnection(t *testing.T) { |
| 144 | nc := badConnection{err: errors.New("boom")} |
nothing calls this directly
no test coverage detected