engine_context_test.go 606 B

12345678910111213141516171819202122232425262728
  1. // Copyright 2017 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build go1.8
  5. package xorm
  6. import (
  7. "context"
  8. "testing"
  9. "time"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestPingContext(t *testing.T) {
  13. assert.NoError(t, prepareEngine())
  14. ctx, canceled := context.WithTimeout(context.Background(), time.Nanosecond)
  15. defer canceled()
  16. time.Sleep(time.Nanosecond)
  17. err := testEngine.(*Engine).PingContext(ctx)
  18. assert.Error(t, err)
  19. assert.Contains(t, err.Error(), "context deadline exceeded")
  20. }