2017-10-31 09:30:01 +00:00
|
|
|
// Copyright 2017 The Xorm Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// +build go1.8
|
|
|
|
|
|
|
|
package xorm
|
|
|
|
|
|
|
|
import (
|
2018-09-23 05:22:18 +00:00
|
|
|
"context"
|
2017-10-31 09:30:01 +00:00
|
|
|
"testing"
|
2018-09-23 05:22:18 +00:00
|
|
|
"time"
|
2017-10-31 09:30:01 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPingContext(t *testing.T) {
|
|
|
|
assert.NoError(t, prepareEngine())
|
|
|
|
|
2019-01-20 03:01:14 +00:00
|
|
|
ctx, canceled := context.WithTimeout(context.Background(), time.Nanosecond)
|
2018-09-23 05:22:18 +00:00
|
|
|
defer canceled()
|
|
|
|
|
2019-07-23 07:35:33 +00:00
|
|
|
time.Sleep(time.Nanosecond)
|
|
|
|
|
2018-09-23 05:22:18 +00:00
|
|
|
err := testEngine.(*Engine).PingContext(ctx)
|
2019-01-20 03:01:14 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Contains(t, err.Error(), "context deadline exceeded")
|
2017-10-31 09:30:01 +00:00
|
|
|
}
|