Add context support for orm
Signed-off-by: Penghui Liao <liaoishere@gmail.com>
This commit is contained in:
@@ -2820,3 +2820,23 @@ func TestCondition(t *testing.T) {
|
||||
throwFail(t, AssertIs(!cycleFlag, true))
|
||||
return
|
||||
}
|
||||
|
||||
func TestContextCanceled(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
user := User{UserName: "slene"}
|
||||
|
||||
err := dORM.ReadWithCtx(ctx, &user, "UserName")
|
||||
throwFail(t, err)
|
||||
|
||||
cancel()
|
||||
err = dORM.ReadWithCtx(ctx, &user, "UserName")
|
||||
throwFail(t, AssertIs(err, context.Canceled))
|
||||
|
||||
ctx, cancel = context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
qs := dORM.QueryTable(user).WithContext(ctx)
|
||||
_, err = qs.Filter("UserName", "slene").Count()
|
||||
throwFail(t, AssertIs(err, context.Canceled))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user