THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
828B

  1. // Copyright 2019 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. package xorm
  5. import (
  6. "context"
  7. "testing"
  8. "time"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func TestQueryContext(t *testing.T) {
  12. type ContextQueryStruct struct {
  13. Id int64
  14. Name string
  15. }
  16. assert.NoError(t, prepareEngine())
  17. assertSync(t, new(ContextQueryStruct))
  18. _, err := testEngine.Insert(&ContextQueryStruct{Name: "1"})
  19. assert.NoError(t, err)
  20. ctx, cancel := context.WithTimeout(context.Background(), time.Nanosecond)
  21. defer cancel()
  22. time.Sleep(time.Nanosecond)
  23. has, err := testEngine.Context(ctx).Exist(&ContextQueryStruct{Name: "1"})
  24. assert.Error(t, err)
  25. assert.Contains(t, err.Error(), "context deadline exceeded")
  26. assert.False(t, has)
  27. }