本文整理匯總了Golang中github.com/cockroachdb/cockroach/pkg/util/leaktest.AfterTest函數的典型用法代碼示例。如果您正苦於以下問題:Golang AfterTest函數的具體用法?Golang AfterTest怎麽用?Golang AfterTest使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了AfterTest函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestRangeLookupWithOpenTransaction
// TestRangeLookupWithOpenTransaction verifies that range lookups are
// done in such a way (e.g. using inconsistent reads) that they
// proceed in the event that a write intent is extant at the meta
// index record being read.
func TestRangeLookupWithOpenTransaction(t *testing.T) {
defer leaktest.AfterTest(t)()
s, _, _ := serverutils.StartServer(t, base.TestServerArgs{})
defer s.Stopper().Stop()
db := createTestClient(t, s.Stopper(), s.ServingAddr())
// Create an intent on the meta1 record by writing directly to the
// engine.
key := testutils.MakeKey(keys.Meta1Prefix, roachpb.KeyMax)
now := s.Clock().Now()
txn := roachpb.NewTransaction("txn", roachpb.Key("foobar"), 0, enginepb.SERIALIZABLE, now, 0)
if err := engine.MVCCPutProto(
context.Background(), s.(*server.TestServer).Engines()[0],
nil, key, now, txn, &roachpb.RangeDescriptor{}); err != nil {
t.Fatal(err)
}
// Now, with an intent pending, attempt (asynchronously) to read
// from an arbitrary key. This will cause the distributed sender to
// do a range lookup, which will encounter the intent. We're
// verifying here that the range lookup doesn't fail with a write
// intent error. If it did, it would go into a deadloop attempting
// to push the transaction, which in turn requires another range
// lookup, etc, ad nauseam.
if _, err := db.Get(context.TODO(), "a"); err != nil {
t.Fatal(err)
}
}
示例2: TestBelowRaftProtos
func TestBelowRaftProtos(t *testing.T) {
defer leaktest.AfterTest(t)()
// Enable the additional checks in TestMain. NB: running this test by itself
// will fail those extra checks - such failures are safe to ignore, so long
// as this test passes when run with the entire package's tests.
verifyBelowRaftProtos = true
slice := make([]byte, 1<<20)
for typ, fix := range belowRaftGoldenProtos {
if b, err := protoutil.Marshal(reflect.New(typ.Elem()).Interface().(proto.Message)); err != nil {
t.Fatal(err)
} else if err := verifyHash(b, fix.emptySum); err != nil {
t.Errorf("%s (empty): %s\n", typ, err)
}
randGen := rand.New(rand.NewSource(goldenSeed))
bytes := slice
numBytes := 0
for i := 0; i < itersPerProto; i++ {
if n, err := marshalTo(fix.populatedConstructor(randGen), bytes); err != nil {
t.Fatal(err)
} else {
bytes = bytes[n:]
numBytes += n
}
}
if err := verifyHash(slice[:numBytes], fix.populatedSum); err != nil {
t.Errorf("%s (populated): %s\n", typ, err)
}
}
}
示例3: 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)
}
}
示例4: TestDropIndexInterleaved
func TestDropIndexInterleaved(t *testing.T) {
defer leaktest.AfterTest(t)()
const chunkSize = 200
params, _ := createTestServerParams()
params.Knobs = base.TestingKnobs{
SQLSchemaChanger: &sql.SchemaChangerTestingKnobs{
BackfillChunkSize: chunkSize,
},
}
s, sqlDB, kvDB := serverutils.StartServer(t, params)
defer s.Stopper().Stop()
numRows := 2*chunkSize + 1
createKVInterleavedTable(t, sqlDB, numRows)
tableDesc := sqlbase.GetTableDescriptor(kvDB, "t", "kv")
tablePrefix := roachpb.Key(keys.MakeTablePrefix(uint32(tableDesc.ID)))
checkKeyCount(t, kvDB, tablePrefix, 3*numRows)
if _, err := sqlDB.Exec(`DROP INDEX [email protected]_idx`); err != nil {
t.Fatal(err)
}
checkKeyCount(t, kvDB, tablePrefix, 2*numRows)
// Ensure that index is not active.
tableDesc = sqlbase.GetTableDescriptor(kvDB, "t", "intlv")
if _, _, err := tableDesc.FindIndexByName("intlv_idx"); err == nil {
t.Fatalf("table descriptor still contains index after index is dropped")
}
}
示例5: TestDropTableInTxn
func TestDropTableInTxn(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.kv (k CHAR PRIMARY KEY, v CHAR);
`); err != nil {
t.Fatal(err)
}
tx, err := sqlDB.Begin()
if err != nil {
t.Fatal(err)
}
if _, err := tx.Exec(`DROP TABLE t.kv`); err != nil {
t.Fatal(err)
}
// We might still be able to read/write in the table inside this transaction
// until the schema changer runs, but we shouldn't be able to ALTER it.
if _, err := tx.Exec(`ALTER TABLE t.kv ADD COLUMN w CHAR`); !testutils.IsError(err,
`table "kv" is being dropped`) {
t.Fatalf("different error than expected: %v", err)
}
// Can't commit after ALTER errored, so we ROLLBACK.
if err := tx.Rollback(); err != nil {
t.Fatal(err)
}
}
示例6: TestRangeIterForward
func TestRangeIterForward(t *testing.T) {
defer leaktest.AfterTest(t)()
stopper := stop.NewStopper()
defer stopper.Stop()
g, clock := makeGossip(t, stopper)
ds := NewDistSender(DistSenderConfig{
Clock: clock,
RangeDescriptorDB: alphaRangeDescriptorDB,
}, g)
ctx := context.Background()
ri := NewRangeIterator(ds)
i := 0
span := roachpb.RSpan{
Key: roachpb.RKey(roachpb.KeyMin),
EndKey: roachpb.RKey([]byte("z")),
}
for ri.Seek(ctx, span.Key, Ascending); ri.Valid(); ri.Next(ctx) {
if !reflect.DeepEqual(alphaRangeDescriptors[i], ri.Desc()) {
t.Fatalf("%d: expected %v; got %v", i, alphaRangeDescriptors[i], ri.Desc())
}
i++
if !ri.NeedAnother(span) {
break
}
}
}
示例7: TestParseTs
// The assertions in this test should also be caught by the integration tests on
// various drivers.
func TestParseTs(t *testing.T) {
defer leaktest.AfterTest(t)()
var parseTsTests = []struct {
strTimestamp string
expected time.Time
}{
// time.RFC3339Nano for github.com/lib/pq.
{"2006-07-08T00:00:00.000000123Z", time.Date(2006, 7, 8, 0, 0, 0, 123, time.FixedZone("UTC", 0))},
// The format accepted by pq.ParseTimestamp.
{"2001-02-03 04:05:06.123-07", time.Date(2001, time.February, 3, 4, 5, 6, 123000000, time.FixedZone("", -7*60*60))},
}
for i, test := range parseTsTests {
parsed, err := parseTs(test.strTimestamp)
if err != nil {
t.Errorf("%d could not parse [%s]: %v", i, test.strTimestamp, err)
continue
}
if !parsed.Equal(test.expected) {
t.Errorf("%d parsing [%s] got [%s] expected [%s]", i, test.strTimestamp, parsed, test.expected)
}
}
}
示例8: TestStorePoolThrottle
func TestStorePoolThrottle(t *testing.T) {
defer leaktest.AfterTest(t)()
stopper, g, _, sp, _ := createTestStorePool(
TestTimeUntilStoreDead, false /* deterministic */, false /* defaultNodeLiveness */)
defer stopper.Stop()
sg := gossiputil.NewStoreGossiper(g)
sg.GossipStores(uniqueStore, t)
{
expected := sp.clock.Now().GoTime().Add(sp.declinedReservationsTimeout)
sp.throttle(throttleDeclined, 1)
sp.mu.Lock()
detail := sp.getStoreDetailLocked(1)
sp.mu.Unlock()
if !detail.throttledUntil.Equal(expected) {
t.Errorf("expected store to have been throttled to %v, found %v",
expected, detail.throttledUntil)
}
}
{
expected := sp.clock.Now().GoTime().Add(sp.failedReservationsTimeout)
sp.throttle(throttleFailed, 1)
sp.mu.Lock()
detail := sp.getStoreDetailLocked(1)
sp.mu.Unlock()
if !detail.throttledUntil.Equal(expected) {
t.Errorf("expected store to have been throttled to %v, found %v",
expected, detail.throttledUntil)
}
}
}
示例9: TestStopperRunTaskPanic
// TestStopperRunTaskPanic ensures that a panic handler can recover panicking
// tasks, and that no tasks are leaked when they panic.
func TestStopperRunTaskPanic(t *testing.T) {
defer leaktest.AfterTest(t)()
ch := make(chan interface{})
s := stop.NewStopper(stop.OnPanic(func(v interface{}) {
ch <- v
}))
// If RunTask were not panic-safe, Stop() would deadlock.
type testFn func()
explode := func() { panic(ch) }
for i, test := range []testFn{
func() {
_ = s.RunTask(explode)
},
func() {
_ = s.RunAsyncTask(context.Background(), func(_ context.Context) { explode() })
},
func() {
_ = s.RunLimitedAsyncTask(
context.Background(),
make(chan struct{}, 1),
true, /* wait */
func(_ context.Context) { explode() },
)
},
func() {
s.RunWorker(explode)
},
} {
go test()
recovered := <-ch
if recovered != ch {
t.Errorf("%d: unexpected recovered value: %+v", i, recovered)
}
}
}
示例10: TestMixedDirections
func TestMixedDirections(t *testing.T) {
defer leaktest.AfterTest(t)()
s, db, cdb := serverutils.StartServer(t, base.TestServerArgs{
UseDatabase: "t",
})
defer s.Stopper().Stop()
rowRanges, tableDesc := setupRanges(db, s.(*server.TestServer), cdb, t)
lr := distsqlplan.NewSpanResolver(
s.DistSender(), s.Gossip(),
s.(*server.TestServer).GetNode().Descriptor,
distsqlplan.BinPackingLeaseHolderChoice)
ctx := context.Background()
it := lr.NewSpanResolverIterator()
spans := []spanWithDir{
orient(kv.Ascending, makeSpan(tableDesc, 11, 15))[0],
orient(kv.Descending, makeSpan(tableDesc, 1, 14))[0],
}
replicas, err := resolveSpans(ctx, it, spans...)
if err != nil {
t.Fatal(err)
}
expected := [][]rngInfo{
{onlyReplica(rowRanges[1])},
{onlyReplica(rowRanges[1]), onlyReplica(rowRanges[0])},
}
if err = expectResolved(replicas, expected...); err != nil {
t.Fatal(err)
}
}
示例11: TestTableNameNotCaseSensitive
// Test that table names are not treated as case sensitive by the name cache.
func TestTableNameNotCaseSensitive(t *testing.T) {
defer leaktest.AfterTest(t)()
s, db, kvDB := serverutils.StartServer(t, base.TestServerArgs{})
defer s.Stopper().Stop()
leaseManager := s.LeaseManager().(*LeaseManager)
if _, err := db.Exec(`
CREATE DATABASE t;
CREATE TABLE t.test (k CHAR PRIMARY KEY, v CHAR);
`); err != nil {
t.Fatal(err)
}
// Populate the name cache.
if _, err := db.Exec("SELECT * FROM t.test;"); err != nil {
t.Fatal(err)
}
tableDesc := sqlbase.GetTableDescriptor(kvDB, "t", "test")
// Check that we can get the table by a different name.
lease := leaseManager.tableNames.get(tableDesc.ParentID, "tEsT", s.Clock())
if lease == nil {
t.Fatalf("no name cache entry")
}
if err := leaseManager.Release(lease); err != nil {
t.Fatal(err)
}
}
示例12: 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)
}
}
示例13: TestReverseScanWithSplitAndMerge
// TestReverseScanWithSplitAndMerge verifies that ReverseScan gets the right results
// across multiple ranges while range splits and merges happen.
func TestReverseScanWithSplitAndMerge(t *testing.T) {
defer leaktest.AfterTest(t)()
s, _, _ := serverutils.StartServer(t, base.TestServerArgs{})
defer s.Stopper().Stop()
db := initReverseScanTestEnv(s, t)
// Case 1: An encounter with a range split.
// Split the range ["b", "e") at "c".
if err := db.AdminSplit(context.TODO(), "c"); err != nil {
t.Fatal(err)
}
// The ReverseScan will run into a stale descriptor.
if rows, err := db.ReverseScan(context.TODO(), "a", "d", 0); err != nil {
t.Fatalf("unexpected error on ReverseScan: %s", err)
} else if l := len(rows); l != 3 {
t.Errorf("expected 3 rows; got %d", l)
}
// Case 2: encounter with range merge .
// Merge the range ["e", "g") and ["g", "\xff\xff") .
if err := db.AdminMerge(context.TODO(), "e"); err != nil {
t.Fatal(err)
}
if rows, err := db.ReverseScan(context.TODO(), "d", "g", 0); err != nil {
t.Fatalf("unexpected error on ReverseScan: %s", err)
} else if l := len(rows); l != 3 {
t.Errorf("expected 3 rows; got %d", l)
}
}
示例14: TestMultiRangeReverseScan
// TestMultiRangeReverseScan verifies that ReverseScan gets the right results
// across multiple ranges.
func TestMultiRangeReverseScan(t *testing.T) {
defer leaktest.AfterTest(t)()
s, _, _ := serverutils.StartServer(t, base.TestServerArgs{})
defer s.Stopper().Stop()
db := initReverseScanTestEnv(s, t)
ctx := context.TODO()
// Case 1: Request.EndKey is in the middle of the range.
if rows, pErr := db.ReverseScan(ctx, "a", "d", 0); pErr != nil {
t.Fatalf("unexpected error on ReverseScan: %s", pErr)
} else if l := len(rows); l != 3 {
t.Errorf("expected 3 rows; got %d", l)
}
if rows, pErr := db.ReverseScan(ctx, "a", "d", 2); pErr != nil {
t.Fatalf("unexpected error on ReverseScan: %s", pErr)
} else if l := len(rows); l != 2 {
t.Errorf("expected 2 rows; got %d", l)
}
// Case 2: Request.EndKey is equal to the EndKey of the range.
if rows, pErr := db.ReverseScan(ctx, "d", "g", 0); pErr != nil {
t.Fatalf("unexpected error on ReverseScan: %s", pErr)
} else if l := len(rows); l != 3 {
t.Errorf("expected 3 rows; got %d", l)
}
}
示例15: TestAbortCountErrorDuringTransaction
// TestErrorDuringTransaction tests that the transaction abort count goes up when a query
// results in an error during a txn.
func TestAbortCountErrorDuringTransaction(t *testing.T) {
defer leaktest.AfterTest(t)()
params, _ := createTestServerParams()
s, sqlDB, _ := serverutils.StartServer(t, params)
defer s.Stopper().Stop()
txn, err := sqlDB.Begin()
if err != nil {
t.Fatal(err)
}
if _, err := txn.Query("SELECT * FROM i_do.not_exist"); err == nil {
t.Fatal("Expected an error but didn't get one")
}
if err := checkCounterEQ(s, sql.MetaTxnAbort, 1); err != nil {
t.Error(err)
}
if err := checkCounterEQ(s, sql.MetaTxnBegin, 1); err != nil {
t.Error(err)
}
if err := checkCounterEQ(s, sql.MetaSelect, 1); err != nil {
t.Error(err)
}
}