conncheck_test.go 826 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
  2. //
  3. // Copyright 2013 The Go-MySQL-Driver Authors. All rights reserved.
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public
  6. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  7. // You can obtain one at http://mozilla.org/MPL/2.0/.
  8. // +build go1.10,!windows
  9. package mysql
  10. import (
  11. "testing"
  12. "time"
  13. )
  14. func TestStaleConnectionChecks(t *testing.T) {
  15. runTests(t, dsn, func(dbt *DBTest) {
  16. dbt.mustExec("SET @@SESSION.wait_timeout = 2")
  17. if err := dbt.db.Ping(); err != nil {
  18. dbt.Fatal(err)
  19. }
  20. // wait for MySQL to close our connection
  21. time.Sleep(3 * time.Second)
  22. tx, err := dbt.db.Begin()
  23. if err != nil {
  24. dbt.Fatal(err)
  25. }
  26. if err := tx.Rollback(); err != nil {
  27. dbt.Fatal(err)
  28. }
  29. })
  30. }