MCPcopy
hub / github.com/go-sql-driver/mysql / TestCleanCancel

Function TestCleanCancel

connection_test.go:117–141  ·  view source on GitHub ↗

TestCleanCancel tests passed context is cancelled at start. No packet should be sent. Connection should keep current status.

(t *testing.T)

Source from the content-addressed store, hash-verified

115// TestCleanCancel tests passed context is cancelled at start.
116// No packet should be sent. Connection should keep current status.
117func 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
143func TestPingMarkBadConnection(t *testing.T) {
144 nc := badConnection{err: errors.New("boom")}

Callers

nothing calls this directly

Calls 4

startWatcherMethod · 0.95
cleanupMethod · 0.95
PingMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected