本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/testutils.IsError函数的典型用法代码示例。如果您正苦于以下问题:Golang IsError函数的具体用法?Golang IsError怎么用?Golang IsError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsError函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestCommitWaitState
// Test that rando commands while in COMMIT_WAIT return a particular error.
func TestCommitWaitState(t *testing.T) {
defer leaktest.AfterTest(t)()
params, _ := createTestServerParams()
s, sqlDB, _ := serverutils.StartServer(t, params)
defer s.Stopper().Stop()
if _, err := sqlDB.Exec(`
CREATE DATABASE t; CREATE TABLE t.test (k INT PRIMARY KEY, v TEXT);
`); err != nil {
t.Fatal(err)
}
tx, err := sqlDB.Begin()
if err != nil {
t.Fatal(err)
}
if _, err := tx.Exec(
"SAVEPOINT cockroach_restart; RELEASE cockroach_restart"); err != nil {
t.Fatal(err)
}
if _, err := tx.Exec("INSERT INTO t.test(k, v) VALUES (0, 'sentinel')"); !testutils.IsError(err, "current transaction is committed") {
t.Fatalf("unexpected error: %v", err)
}
// Rollback should respond with a COMMIT command tag.
if err := tx.Rollback(); !testutils.IsError(err, "unexpected command tag COMMIT") {
t.Fatalf("unexpected error: %v", err)
}
}
开发者ID:veteranlu,项目名称:cockroach,代码行数:29,代码来源:txn_restart_test.go
示例2: TestRollbackToSavepointStatement
// TestRollbackToSavepointStatement tests that issuing a RESTART outside of a
// txn produces the proper error.
func TestRollbackToSavepointStatement(t *testing.T) {
defer leaktest.AfterTest(t)()
params, _ := createTestServerParams()
s, sqlDB, _ := serverutils.StartServer(t, params)
defer s.Stopper().Stop()
// ROLLBACK TO SAVEPOINT without a transaction
_, err := sqlDB.Exec("ROLLBACK TO SAVEPOINT cockroach_restart")
if !testutils.IsError(err, "the transaction is not in a retriable state") {
t.Fatalf("unexpected error: %v", err)
}
// ROLLBACK TO SAVEPOINT with a wrong name
_, err = sqlDB.Exec("ROLLBACK TO SAVEPOINT foo")
if !testutils.IsError(err, "SAVEPOINT not supported except for COCKROACH_RESTART") {
t.Fatalf("unexpected error: %v", err)
}
// ROLLBACK TO SAVEPOINT in a non-retriable transaction
tx, err := sqlDB.Begin()
if err != nil {
t.Fatal(err)
}
if _, err := tx.Exec("SAVEPOINT cockroach_restart"); err != nil {
t.Fatal(err)
}
if _, err := tx.Exec("BOGUS SQL STATEMENT"); !testutils.IsError(err, `syntax error at or near "BOGUS"`) {
t.Fatalf("unexpected error: %v", err)
}
if _, err := tx.Exec("ROLLBACK TO SAVEPOINT cockroach_restart"); !testutils.IsError(
err, "SAVEPOINT COCKROACH_RESTART has not been used or a non-retriable error was encountered",
) {
t.Fatalf("unexpected error: %v", err)
}
}
开发者ID:veteranlu,项目名称:cockroach,代码行数:37,代码来源:txn_restart_test.go
示例3: TestBadRequest
func TestBadRequest(t *testing.T) {
defer leaktest.AfterTest(t)()
s, _, _ := serverutils.StartServer(t, base.TestServerArgs{})
defer s.Stopper().Stop()
db := createTestClient(t, s.Stopper(), s.ServingAddr())
ctx := context.TODO()
// Write key "a".
if err := db.Put(ctx, "a", "value"); err != nil {
t.Fatal(err)
}
if _, err := db.Scan(ctx, "a", "a", 0); !testutils.IsError(err, "truncation resulted in empty batch") {
t.Fatalf("unexpected error on scan with startkey == endkey: %v", err)
}
if _, err := db.ReverseScan(ctx, "a", "a", 0); !testutils.IsError(err, "truncation resulted in empty batch") {
t.Fatalf("unexpected error on reverse scan with startkey == endkey: %v", err)
}
if err := db.DelRange(ctx, "x", "a"); !testutils.IsError(err, "truncation resulted in empty batch") {
t.Fatalf("unexpected error on deletion on [x, a): %v", err)
}
if err := db.DelRange(ctx, "", "z"); !testutils.IsError(err, "must be greater than LocalMax") {
t.Fatalf("unexpected error on deletion on [KeyMin, z): %v", err)
}
}
开发者ID:knz,项目名称:cockroach,代码行数:28,代码来源:dist_sender_server_test.go
示例4: TestBatchError
// TestBatchError verifies that Range returns an error if a request has an invalid range.
func TestBatchError(t *testing.T) {
testCases := []struct {
req [2]string
errMsg string
}{
{
req: [2]string{"\xff\xff\xff\xff", "a"},
errMsg: "must be less than KeyMax",
},
{
req: [2]string{"a", "\xff\xff\xff\xff"},
errMsg: "must be less than or equal to KeyMax",
},
}
for i, c := range testCases {
var ba roachpb.BatchRequest
ba.Add(&roachpb.ScanRequest{Span: roachpb.Span{Key: roachpb.Key(c.req[0]), EndKey: roachpb.Key(c.req[1])}})
if _, err := Range(ba); !testutils.IsError(err, c.errMsg) {
t.Errorf("%d: unexpected error %v", i, err)
}
}
// Test a case where a non-range request has an end key.
var ba roachpb.BatchRequest
ba.Add(&roachpb.GetRequest{Span: roachpb.Span{Key: roachpb.Key("a"), EndKey: roachpb.Key("b")}})
if _, err := Range(ba); !testutils.IsError(err, "end key specified for non-range operation") {
t.Errorf("unexpected error %v", err)
}
}
开发者ID:hvaara,项目名称:cockroach,代码行数:31,代码来源:keys_test.go
示例5: TestCommandsWhileTableBeingDropped
// Test commands while a table is being dropped.
func TestCommandsWhileTableBeingDropped(t *testing.T) {
defer leaktest.AfterTest(t)()
params, _ := createTestServerParams()
// Block schema changers so that the table we're about to DROP is not
// actually dropped; it will be left in the "deleted" state.
params.Knobs = base.TestingKnobs{
SQLSchemaChanger: &sql.SchemaChangerTestingKnobs{
SyncFilter: func(tscc sql.TestingSchemaChangerCollection) {
tscc.ClearSchemaChangers()
},
AsyncExecNotification: asyncSchemaChangerDisabled,
},
}
s, db, _ := serverutils.StartServer(t, params)
defer s.Stopper().Stop()
sql := `
CREATE DATABASE test;
CREATE TABLE test.t(a INT PRIMARY KEY);
`
if _, err := db.Exec(sql); err != nil {
t.Fatal(err)
}
// DROP the table
if _, err := db.Exec(`DROP TABLE test.t`); err != nil {
t.Fatal(err)
}
// Check that SHOW TABLES marks a dropped table with the " (dropped)"
// suffix.
rows, err := db.Query(`SHOW TABLES FROM test`)
if err != nil {
t.Fatal(err)
}
defer rows.Close()
if !rows.Next() {
t.Fatal("table invisible through SHOW TABLES")
}
var val string
if err := rows.Scan(&val); err != nil {
t.Errorf("row scan failed: %s", err)
}
if val != "t (dropped)" {
t.Fatalf("table = %s", val)
}
// Check that CREATE TABLE with the same name returns a proper error.
if _, err := db.Exec(`CREATE TABLE test.t(a INT PRIMARY KEY)`); !testutils.IsError(err, `relation "t" already exists`) {
t.Fatal(err)
}
// Check that DROP TABLE with the same name returns a proper error.
if _, err := db.Exec(`DROP TABLE test.t`); !testutils.IsError(err, `table "t" is being dropped`) {
t.Fatal(err)
}
}
开发者ID:knz,项目名称:cockroach,代码行数:59,代码来源:drop_test.go
示例6: runTestTxn
// Returns true on retriable errors.
func runTestTxn(
t *testing.T,
magicVals *filterVals,
expectedErr string,
sqlDB *gosql.DB,
tx *gosql.Tx,
sentinelInsert string,
) bool {
retriesNeeded :=
(magicVals.restartCounts["boulanger"] + magicVals.abortCounts["boulanger"]) > 0
if retriesNeeded {
_, err := tx.Exec("INSERT INTO t.test(k, v) VALUES (1, 'boulanger')")
if !testutils.IsError(err, expectedErr) {
t.Fatalf("unexpected error: %v", err)
}
return isRetryableErr(err)
}
// Now the INSERT should succeed.
if _, err := tx.Exec(
"DELETE FROM t.test WHERE true;" + sentinelInsert,
); err != nil {
t.Fatal(err)
}
_, err := tx.Exec("RELEASE SAVEPOINT cockroach_restart")
return isRetryableErr(err)
}
开发者ID:veteranlu,项目名称:cockroach,代码行数:28,代码来源:txn_restart_test.go
示例7: TestNonRetryableErrorOnCommit
// TestNonRetryableErrorOnCommit verifies that a non-retryable error from the
// execution of EndTransactionRequests is propagated to the client.
func TestNonRetryableErrorOnCommit(t *testing.T) {
defer leaktest.AfterTest(t)()
params, cmdFilters := createTestServerParams()
s, sqlDB, _ := serverutils.StartServer(t, params)
defer s.Stopper().Stop()
hitError := false
cleanupFilter := cmdFilters.AppendFilter(
func(args storagebase.FilterArgs) *roachpb.Error {
if req, ok := args.Req.(*roachpb.EndTransactionRequest); ok {
if bytes.Contains(req.Key, []byte(keys.DescIDGenerator)) {
hitError = true
return roachpb.NewErrorWithTxn(fmt.Errorf("testError"), args.Hdr.Txn)
}
}
return nil
}, false)
defer cleanupFilter()
if _, err := sqlDB.Exec("CREATE DATABASE t"); !testutils.IsError(err, "pq: testError") {
t.Errorf("unexpected error %v", err)
}
if !hitError {
t.Errorf("expected to hit error, but it didn't happen")
}
}
开发者ID:veteranlu,项目名称:cockroach,代码行数:29,代码来源:txn_restart_test.go
示例8: TestRocksDBOpenWithVersions
// TestRocksDBOpenWithVersions verifies the version checking in Open()
// functions correctly.
func TestRocksDBOpenWithVersions(t *testing.T) {
defer leaktest.AfterTest(t)()
testCases := []struct {
hasFile bool
ver Version
expectedErr string
}{
{false, Version{}, ""},
{true, Version{versionCurrent}, ""},
{true, Version{versionMinimum}, ""},
{true, Version{-1}, "incompatible rocksdb data version, current:1, on disk:-1, minimum:0"},
{true, Version{2}, "incompatible rocksdb data version, current:1, on disk:2, minimum:0"},
}
for i, testCase := range testCases {
err := openRocksDBWithVersion(t, testCase.hasFile, testCase.ver)
if err == nil && len(testCase.expectedErr) == 0 {
continue
}
if !testutils.IsError(err, testCase.expectedErr) {
t.Errorf("%d: expected error '%s', actual '%v'", i, testCase.expectedErr, err)
}
}
}
开发者ID:hvaara,项目名称:cockroach,代码行数:27,代码来源:rocksdb_test.go
示例9: TestTxnCoordIdempotentCleanup
// TestTxnCoordIdempotentCleanup verifies that cleanupTxnLocked is idempotent.
func TestTxnCoordIdempotentCleanup(t *testing.T) {
defer leaktest.AfterTest(t)()
s, sender := createTestDB(t)
defer s.Stop()
defer teardownHeartbeats(sender)
txn := client.NewTxn(context.Background(), *s.DB)
ba := txn.NewBatch()
ba.Put(roachpb.Key("a"), []byte("value"))
if err := txn.Run(ba); err != nil {
t.Fatal(err)
}
sender.Lock()
// Clean up twice successively.
sender.cleanupTxnLocked(context.Background(), txn.Proto)
sender.cleanupTxnLocked(context.Background(), txn.Proto)
sender.Unlock()
// For good measure, try to commit (which cleans up once more if it
// succeeds, which it may not if the previous cleanup has already
// terminated the heartbeat goroutine)
ba = txn.NewBatch()
ba.AddRawRequest(&roachpb.EndTransactionRequest{})
err := txn.Run(ba)
if err != nil && !testutils.IsError(err, errNoState.Error()) {
t.Fatal(err)
}
}
开发者ID:hvaara,项目名称:cockroach,代码行数:30,代码来源:txn_coord_sender_test.go
示例10: TestTxnAbandonCount
func TestTxnAbandonCount(t *testing.T) {
defer leaktest.AfterTest(t)()
manual, sender, cleanupFn := setupMetricsTest(t)
defer cleanupFn()
value := []byte("value")
db := client.NewDB(sender)
// Test abandoned transaction by making the client timeout ridiculously short. We also set
// the sender to heartbeat very frequently, because the heartbeat detects and tears down
// abandoned transactions.
sender.heartbeatInterval = 2 * time.Millisecond
sender.clientTimeout = 1 * time.Millisecond
if err := db.Txn(context.TODO(), func(txn *client.Txn) error {
key := []byte("key-abandon")
if err := txn.SetIsolation(enginepb.SNAPSHOT); err != nil {
return err
}
if err := txn.Put(key, value); err != nil {
return err
}
manual.Increment(int64(sender.clientTimeout + sender.heartbeatInterval*2))
checkTxnMetrics(t, sender, "abandon txn", 0, 0, 1, 0, 0)
return nil
}); !testutils.IsError(err, "writing transaction timed out") {
t.Fatalf("unexpected error: %v", err)
}
}
开发者ID:hvaara,项目名称:cockroach,代码行数:32,代码来源:txn_coord_sender_test.go
示例11: TestVerifyClockOffset
func TestVerifyClockOffset(t *testing.T) {
defer leaktest.AfterTest(t)()
clock := hlc.NewClock(hlc.NewManualClock(123).UnixNano, 50*time.Nanosecond)
monitor := newRemoteClockMonitor(clock, time.Hour)
for idx, tc := range []struct {
offsets []RemoteOffset
expectedError bool
}{
// no error if no offsets.
{[]RemoteOffset{}, false},
// no error when a majority of offsets are under the maximum tolerated offset.
{[]RemoteOffset{{Offset: 20, Uncertainty: 10}, {Offset: 48, Uncertainty: 20}, {Offset: 61, Uncertainty: 25}, {Offset: 91, Uncertainty: 31}}, false},
// error when less than a majority of offsets are under the maximum tolerated offset.
{[]RemoteOffset{{Offset: 20, Uncertainty: 10}, {Offset: 58, Uncertainty: 20}, {Offset: 85, Uncertainty: 25}, {Offset: 91, Uncertainty: 31}}, true},
} {
monitor.mu.offsets = make(map[string]RemoteOffset)
for i, offset := range tc.offsets {
monitor.mu.offsets[strconv.Itoa(i)] = offset
}
if tc.expectedError {
if err := monitor.VerifyClockOffset(context.TODO()); !testutils.IsError(err, errOffsetGreaterThanMaxOffset) {
t.Errorf("%d: unexpected error %v", idx, err)
}
} else {
if err := monitor.VerifyClockOffset(context.TODO()); err != nil {
t.Errorf("%d: unexpected error %s", idx, err)
}
}
}
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:33,代码来源:clock_offset_test.go
示例12: TestHealthAPI
func TestHealthAPI(t *testing.T) {
defer leaktest.AfterTest(t)()
s, _, _ := serverutils.StartServer(t, base.TestServerArgs{})
defer s.Stopper().Stop()
// We need to retry because the node ID isn't set until after
// bootstrapping.
testutils.SucceedsSoon(t, func() error {
var resp serverpb.HealthResponse
return getAdminJSONProto(s, "health", &resp)
})
// Expire this node's liveness record by pausing heartbeats and advancing the
// server's clock.
ts := s.(*TestServer)
ts.nodeLiveness.PauseHeartbeat(true)
self, err := ts.nodeLiveness.Self()
if err != nil {
t.Fatal(err)
}
s.Clock().Update(self.Expiration.Add(1, 0))
expected := "node is not live"
var resp serverpb.HealthResponse
if err := getAdminJSONProto(s, "health", &resp); !testutils.IsError(err, expected) {
t.Errorf("expected %q error, got %v", expected, err)
}
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:28,代码来源:admin_test.go
示例13: TestSendNext_AllRetryableApplicationErrors
func TestSendNext_AllRetryableApplicationErrors(t *testing.T) {
defer leaktest.AfterTest(t)()
doneChans, sendChan, stopper := setupSendNextTest(t)
defer stopper.Stop()
// All replicas finish with a retryable error.
for _, ch := range doneChans {
ch <- BatchCall{
Reply: &roachpb.BatchResponse{
BatchResponse_Header: roachpb.BatchResponse_Header{
Error: roachpb.NewError(roachpb.NewRangeNotFoundError(1)),
},
},
}
}
// The client send finishes with one of the errors, wrapped in a SendError.
bc := <-sendChan
if bc.Err == nil {
t.Fatalf("expected SendError, got err=nil and reply=%s", bc.Reply)
} else if _, ok := bc.Err.(*roachpb.SendError); !ok {
t.Fatalf("expected SendError, got err=%s", bc.Err)
} else if exp := "range 1 was not found"; !testutils.IsError(bc.Err, exp) {
t.Errorf("expected SendError to contain %q, but got %v", exp, bc.Err)
}
}
开发者ID:hvaara,项目名称:cockroach,代码行数:27,代码来源:send_test.go
示例14: TestWrongTxnRetry
// Tests that a retryable error for an inner txn doesn't cause the outer txn to
// be retried.
func TestWrongTxnRetry(t *testing.T) {
defer leaktest.AfterTest(t)()
db := NewDB(newTestSender(nil, nil))
var retries int
txnClosure := func(outerTxn *Txn) error {
log.Infof(context.Background(), "outer retry")
retries++
// Ensure the KV transaction is created.
if err := outerTxn.Put("a", "b"); err != nil {
t.Fatal(err)
}
var execOpt TxnExecOptions
execOpt.AutoRetry = false
err := outerTxn.Exec(
execOpt,
func(innerTxn *Txn, opt *TxnExecOptions) error {
// Ensure the KV transaction is created.
if err := innerTxn.Put("x", "y"); err != nil {
t.Fatal(err)
}
return roachpb.NewErrorWithTxn(&roachpb.TransactionPushError{
PusheeTxn: outerTxn.Proto}, &innerTxn.Proto).GoError()
})
return err
}
if err := db.Txn(context.TODO(), txnClosure); !testutils.IsError(err, "failed to push") {
t.Fatal(err)
}
if retries != 1 {
t.Fatalf("unexpected retries: %d", retries)
}
}
开发者ID:hvaara,项目名称:cockroach,代码行数:36,代码来源:txn_test.go
示例15: runCommandAndExpireLease
func runCommandAndExpireLease(
t *testing.T, leaseManager *csql.LeaseManager, clock *hlc.Clock, sqlDB *gosql.DB, sql string,
) {
// Run a transaction that lets its table lease expire.
txn, err := sqlDB.Begin()
if err != nil {
t.Fatal(err)
}
// Use snapshot isolation so that the transaction is pushed without being
// restarted.
if _, err := txn.Exec("SET TRANSACTION ISOLATION LEVEL SNAPSHOT"); err != nil {
t.Fatal(err)
}
if _, err := txn.Exec(sql); err != nil {
t.Fatal(err)
}
leaseManager.ExpireLeases(clock)
// Run another transaction that pushes the above transaction.
if _, err := sqlDB.Query("SELECT * FROM t.kv"); err != nil {
t.Fatal(err)
}
// Commit and see the aborted txn.
if err := txn.Commit(); !testutils.IsError(err, "pq: restart transaction: txn aborted") {
t.Fatalf("%s, err = %v", sql, err)
}
}
开发者ID:knz,项目名称:cockroach,代码行数:29,代码来源:lease_test.go
示例16: TestAuthentication
// TestAuthentication tests authentication for the KV endpoint.
func TestAuthentication(t *testing.T) {
defer leaktest.AfterTest(t)()
s, _, _ := serverutils.StartServer(t, base.TestServerArgs{})
defer s.Stopper().Stop()
b1 := &client.Batch{}
b1.Put("a", "b")
// Create a node user client and call Run() on it which lets us build our own
// request, specifying the user.
db1 := createTestClientForUser(t, s, security.NodeUser)
if err := db1.Run(context.TODO(), b1); err != nil {
t.Fatal(err)
}
b2 := &client.Batch{}
b2.Put("c", "d")
// Try again, but this time with certs for a non-node user (even the root
// user has no KV permissions).
db2 := createTestClientForUser(t, s, security.RootUser)
if err := db2.Run(context.TODO(), b2); !testutils.IsError(err, "is not allowed") {
t.Fatal(err)
}
}
开发者ID:hvaara,项目名称:cockroach,代码行数:26,代码来源:db_test.go
示例17: TestClientForwardUnresolved
// TestClientForwardUnresolved verifies that a client does not resolve a forward
// address prematurely.
func TestClientForwardUnresolved(t *testing.T) {
defer leaktest.AfterTest(t)()
stopper := stop.NewStopper()
defer stopper.Stop()
const nodeID = 1
local := startGossip(nodeID, stopper, t, metric.NewRegistry())
addr := local.GetNodeAddr()
client := newClient(log.AmbientContext{}, addr, makeMetrics()) // never started
newAddr := util.UnresolvedAddr{
NetworkField: "tcp",
AddressField: "localhost:2345",
}
reply := &Response{
NodeID: nodeID,
Addr: *addr,
AlternateNodeID: nodeID + 1,
AlternateAddr: &newAddr,
}
if err := client.handleResponse(
context.TODO(), local, reply,
); !testutils.IsError(err, "received forward") {
t.Fatal(err)
}
if !proto.Equal(client.forwardAddr, &newAddr) {
t.Fatalf("unexpected forward address %v, expected %v", client.forwardAddr, &newAddr)
}
}
开发者ID:knz,项目名称:cockroach,代码行数:31,代码来源:client_test.go
示例18: TestTxnAbortCount
func TestTxnAbortCount(t *testing.T) {
defer leaktest.AfterTest(t)()
_, sender, cleanupFn := setupMetricsTest(t)
defer cleanupFn()
value := []byte("value")
db := client.NewDB(sender)
intentionalErrText := "intentional error to cause abort"
// Test aborted transaction.
if err := db.Txn(context.TODO(), func(txn *client.Txn) error {
key := []byte("key-abort")
if err := txn.SetIsolation(enginepb.SNAPSHOT); err != nil {
return err
}
if err := txn.Put(key, value); err != nil {
t.Fatal(err)
}
return errors.New(intentionalErrText)
}); !testutils.IsError(err, intentionalErrText) {
t.Fatalf("unexpected error: %v", err)
}
teardownHeartbeats(sender)
checkTxnMetrics(t, sender, "abort txn", 0, 0, 0, 1, 0)
}
开发者ID:hvaara,项目名称:cockroach,代码行数:28,代码来源:txn_coord_sender_test.go
示例19: TestScanError
func TestScanError(t *testing.T) {
testData := []struct {
sql string
err string
}{
{`1e`, "invalid floating point literal"},
{`1e-`, "invalid floating point literal"},
{`1e+`, "invalid floating point literal"},
{`0x`, "invalid hexadecimal numeric literal"},
{`1x`, "invalid hexadecimal numeric literal"},
{`1.x`, "invalid hexadecimal numeric literal"},
{`1.0x`, "invalid hexadecimal numeric literal"},
{`0x0x`, "invalid hexadecimal numeric literal"},
{`00x0x`, "invalid hexadecimal numeric literal"},
{`08`, "could not make constant int from literal \"08\""},
{`x'zzz'`, "invalid hexadecimal string literal"},
{`X'zzz'`, "invalid hexadecimal string literal"},
{`x'beef\x41'`, "invalid hexadecimal string literal"},
{`X'beef\x41\x41'`, "invalid hexadecimal string literal"},
{`x'''1'''`, "invalid hexadecimal string literal"},
{`$9223372036854775809`, "integer value out of range"},
}
for _, d := range testData {
s := MakeScanner(d.sql, Traditional)
var lval sqlSymType
id := s.Lex(&lval)
if id != ERROR {
t.Errorf("%s: expected ERROR, but found %d", d.sql, id)
}
if !testutils.IsError(errors.New(lval.str), d.err) {
t.Errorf("%s: expected %s, but found %v", d.sql, d.err, lval.str)
}
}
}
开发者ID:veteranlu,项目名称:cockroach,代码行数:34,代码来源:scan_test.go
示例20: TestAcquireAndRelease
func TestAcquireAndRelease(t *testing.T) {
defer leaktest.AfterTest(t)()
s, db := setup(t)
defer s.Stopper().Stop()
ctx := context.Background()
manual := hlc.NewManualClock(123)
clock := hlc.NewClock(manual.UnixNano, time.Nanosecond)
lm := client.NewLeaseManager(db, clock, client.LeaseManagerOptions{ClientID: clientID1})
l, err := lm.AcquireLease(ctx, leaseKey)
if err != nil {
t.Fatal(err)
}
if err := lm.ReleaseLease(ctx, l); err != nil {
t.Fatal(err)
}
if err := lm.ReleaseLease(ctx, l); !testutils.IsError(err, "unexpected value") {
t.Fatal(err)
}
l, err = lm.AcquireLease(ctx, leaseKey)
if err != nil {
t.Fatal(err)
}
if err := lm.ReleaseLease(ctx, l); err != nil {
t.Fatal(err)
}
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:29,代码来源:lease_test.go
注:本文中的github.com/cockroachdb/cockroach/pkg/testutils.IsError函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论