func TestPanics(t *testing.T) { require.Panics(t, func() { New().Add(0, 0) }, "Zeros") require.Panics(t, func() { New().Add(0, 1) }, "Zero duration") require.Panics(t, func() { New().Add(1, 0) }, "Zero sleep") require.Panics(t, func() { New().Add(1, 2) }, "sleep > duration") require.Panics(t, func() { New().Add(10, 8) }, "duration % sleep") }
func TestExclusiveLock(t *testing.T) { el := makeExclusiveLock() el.lock() defer el.unlock() // This must leave el unlocked. require.Panics(t, func() { el.lock() }) }
func TestLeveledMutexIncorrect(t *testing.T) { mu1 := makeLeveledMutex(mutexLevel(testFirst), &sync.Mutex{}) mu2 := makeLeveledMutex(mutexLevel(testSecond), &sync.Mutex{}) mu3 := makeLeveledMutex(mutexLevel(testThird), &sync.Mutex{}) state := makeLevelState(testMutexLevelToString) require.Panics(t, func() { mu1.AssertLocked(state) }) mu2.Lock(state) require.Panics(t, func() { mu2.AssertUnlocked(state) }) defer func() { mu2.Unlock(state) require.Panics(t, func() { mu2.AssertLocked(state) }) }() // This must leave mu1 unlocked. require.Panics(t, func() { mu1.Lock(state) }) mu3.Lock(state) defer mu3.Unlock(state) // This must leave mu2 locked. require.Panics(t, func() { mu2.Unlock(state) }) }
func TestOwner(t *testing.T) { ring1 := New(start, end, peer1name) require.True(t, ring1.Contains(start), "start should be in ring") require.False(t, ring1.Contains(end), "end should not be in ring") require.Equal(t, router.UnknownPeerName, ring1.Owner(start)) ring1.ClaimItAll() ring1.GrantRangeToHost(middle, end, peer2name) require.Equal(t, peer1name, ring1.Owner(start)) require.Equal(t, peer2name, ring1.Owner(middle)) require.Panics(t, func() { ring1.Owner(end) }) }
func TestEndToEnd(t *testing.T) { tMock := testingTMock{t, 0} dir, err := ioutil.TempDir("", "yarpcgorecorder") if err != nil { t.Fatal(err) } defer os.RemoveAll(dir) // clean up // First we double check that our cache is empty. recorder := NewRecorder(&tMock, RecordMode(Replay), RecordsPath(dir)) withDisconnectedClient(t, recorder, func(client raw.Client) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() require.Panics(t, func() { client.Call(ctx, yarpc.NewReqMeta().Procedure("hello"), []byte("Hello")) }) assert.Equal(t, tMock.fatalCount, 1) }) // Now let's record our call. recorder = NewRecorder(&tMock, RecordMode(Overwrite), RecordsPath(dir)) withConnectedClient(t, recorder, func(client raw.Client) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() rbody, _, err := client.Call(ctx, yarpc.NewReqMeta().Procedure("hello"), []byte("Hello")) require.NoError(t, err) assert.Equal(t, rbody, []byte("Hello, World")) }) // Now replay the call. recorder = NewRecorder(&tMock, RecordMode(Replay), RecordsPath(dir)) withDisconnectedClient(t, recorder, func(client raw.Client) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() rbody, _, err := client.Call(ctx, yarpc.NewReqMeta().Procedure("hello"), []byte("Hello")) require.NoError(t, err) assert.Equal(t, rbody, []byte("Hello, World")) }) }
func TestInsert(t *testing.T) { ring := New(start, end, peer1name) ring.Entries = []*entry{{Token: start, Peer: peer1name, Free: 255}} require.Panics(t, func() { ring.Entries.insert(entry{Token: start, Peer: peer1name}) }) ring.Entries.entry(0).Free = 0 ring.Entries.insert(entry{Token: dot245, Peer: peer1name}) ring2 := New(start, end, peer1name) ring2.Entries = []*entry{{Token: start, Peer: peer1name, Free: 0}, {Token: dot245, Peer: peer1name}} require.Equal(t, ring2, ring) ring.Entries.insert(entry{Token: dot10, Peer: peer1name}) ring2.Entries = []*entry{{Token: start, Peer: peer1name, Free: 0}, {Token: dot10, Peer: peer1name}, {Token: dot245, Peer: peer1name}} require.Equal(t, ring2, ring) }
func TestEmptyReplay(t *testing.T) { tMock := testingTMock{t, 0} dir, err := ioutil.TempDir("", "yarpcgorecorder") if err != nil { t.Fatal(err) } defer os.RemoveAll(dir) // clean up recorder := NewRecorder(&tMock, RecordMode(Replay), RecordsPath(dir)) withDisconnectedClient(t, recorder, func(client raw.Client) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() require.Panics(t, func() { client.Call(ctx, yarpc.NewReqMeta().Procedure("hello"), []byte("Hello")) }) assert.Equal(t, tMock.fatalCount, 1) }) }
func TestInsert(t *testing.T) { ring := New(start, end, peer1name) ring.Entries = []*entry{{Token: start, Peer: peer1name, Free: 255}} require.Panics(t, func() { ring.Entries.insert(entry{Token: start, Peer: peer1name}) }) ring.Entries.entry(0).Free = 0 ring.Entries.insert(entry{Token: dot245, Peer: peer1name}) check := []RangeInfo{ {Peer: peer1name, Range: address.Range{Start: start, End: dot245}}, {Peer: peer1name, Range: address.Range{Start: dot245, End: end}}, } require.Equal(t, check, ring.AllRangeInfo()) ring.Entries.insert(entry{Token: dot10, Peer: peer1name}) check2 := []RangeInfo{ {Peer: peer1name, Range: address.Range{Start: start, End: dot10}}, {Peer: peer1name, Range: address.Range{Start: dot10, End: dot245}}, {Peer: peer1name, Range: address.Range{Start: dot245, End: end}}, } require.Equal(t, check2, ring.AllRangeInfo()) }
func TestLeveledRWMutexIncorrect(t *testing.T) { mu1 := makeLeveledRWMutex(mutexLevel(testFirst), &sync.RWMutex{}) mu2 := makeLeveledRWMutex(mutexLevel(testSecond), &sync.RWMutex{}) mu3 := makeLeveledRWMutex(mutexLevel(testThird), &sync.RWMutex{}) state := makeLevelState(testMutexLevelToString) mu2.RLock(state) defer mu2.RUnlock(state) // This must leave mu2 read-locked. require.Panics(t, func() { mu2.RLock(state) }) // These must leave mu1 unlocked. require.Panics(t, func() { mu1.RLock(state) }) require.Panics(t, func() { mu1.Lock(state) }) mu3.Lock(state) defer mu3.Unlock(state) // This must leave mu3 locked. require.Panics(t, func() { mu3.RUnlock(state) }) // These must leave mu2 read-locked. require.Panics(t, func() { mu2.Unlock(state) }) require.Panics(t, func() { mu2.RUnlock(state) }) }
func TestSingletonToNonProviderPanics(t *testing.T) { i := New() require.Panics(t, func() { i.MustBind(Singleton(1)) }) }
func TestNewWorkItemRelationshipsLinksControllerDBNull(t *testing.T) { require.Panics(t, func() { NewWorkItemRelationshipsLinksController(nil, nil) }) }
func TestNewWorkItemLinkControllerDBNull(t *testing.T) { require.Panics(t, func() { NewWorkItemLinkController(nil, nil) }) }