Skip to content

Commit df98674

Browse files
authored
Merge pull request #1 from vimeo/delete_non_fakeclock_tests
Remove non-fake-clock tests
2 parents d2ca26a + d171f01 commit df98674

File tree

1 file changed

+0
-108
lines changed

1 file changed

+0
-108
lines changed

campaign_test.go

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -19,114 +19,6 @@ func init() {
1919
rand.Seed(int64(os.Getpid()) * time.Now().UnixNano())
2020
}
2121

22-
func TestAcquireTrivialUncontended(t *testing.T) {
23-
t.Parallel()
24-
ctx, cancel := context.WithCancel(context.Background())
25-
defer cancel()
26-
d := memory.NewDecider()
27-
elected := atomicBool{}
28-
onElectedCalls := 0
29-
30-
c := Config{
31-
Decider: d,
32-
HostPort: "127.0.0.1:8080",
33-
LeaderID: "yabadabadoo",
34-
OnElected: func(ctx context.Context, tv *TimeView) {
35-
if elected.get() {
36-
t.Error("OnElected called while still elected")
37-
}
38-
elected.set(true)
39-
onElectedCalls++
40-
// we've run (and won), let this run for a bit longer
41-
// then cancel the context (set it just longer than
42-
// half the term-length so we can extend the lease ).
43-
time.AfterFunc(time.Millisecond*16, cancel)
44-
},
45-
OnOusting: func(ctx context.Context) {
46-
elected.set(false)
47-
},
48-
LeaderChanged: func(ctx context.Context, entry entry.RaceEntry) {
49-
},
50-
TermLength: time.Millisecond * 30,
51-
MaxClockSkew: time.Microsecond,
52-
}
53-
54-
if err := c.Acquire(ctx); err != context.Canceled {
55-
t.Errorf("failed to acquire: %s", err)
56-
}
57-
if onElectedCalls != 1 {
58-
t.Errorf("unexpected number of OnElected calls: %d", onElectedCalls)
59-
}
60-
}
61-
62-
func TestAcquireTrivialWithMinorContention(t *testing.T) {
63-
t.Parallel()
64-
ctx, cancel := context.WithCancel(context.Background())
65-
defer cancel()
66-
d := memory.NewDecider()
67-
elected := atomicBool{}
68-
onElectedCalls := 0
69-
wg := sync.WaitGroup{}
70-
defer wg.Wait()
71-
72-
loserConfig := Config{
73-
OnElected: func(context.Context, *TimeView) { t.Error("unexpected election win of loser") },
74-
LeaderChanged: func(_ context.Context, e entry.RaceEntry) { t.Logf("lost election: %+v", e); cancel() },
75-
LeaderID: "nottheleader",
76-
HostPort: "127.0.0.2:7123",
77-
Decider: d,
78-
TermLength: time.Millisecond * 30,
79-
ConnectionParams: []byte("bimbat"),
80-
MaxClockSkew: time.Microsecond,
81-
}
82-
const realleaderID = "yabadabadoo"
83-
const realLeaderConnectionParams = "boodle_doodle"
84-
85-
c := Config{
86-
Decider: d,
87-
HostPort: "127.0.0.1:8080",
88-
LeaderID: realleaderID,
89-
OnElected: func(ctx context.Context, tv *TimeView) {
90-
if elected.get() {
91-
t.Error("OnElected called while still elected")
92-
}
93-
elected.set(true)
94-
onElectedCalls++
95-
// now that we've run and won, spin off another
96-
// goroutine with a loser to contend on the lock.
97-
wg.Add(1)
98-
go func() {
99-
defer wg.Done()
100-
if err := loserConfig.Acquire(ctx); err != context.Canceled {
101-
t.Errorf("non-cancel error: %s", err)
102-
}
103-
104-
}()
105-
},
106-
OnOusting: func(ctx context.Context) {
107-
elected.set(false)
108-
},
109-
LeaderChanged: func(ctx context.Context, rentry entry.RaceEntry) {
110-
if rentry.LeaderID != realleaderID && rentry.ElectionNumber != entry.NoElections {
111-
t.Errorf("wrong leader grabbed lock: %q", rentry.LeaderID)
112-
}
113-
if string(rentry.ConnectionParams) != realLeaderConnectionParams && rentry.ElectionNumber != entry.NoElections {
114-
t.Errorf("wrong ConnectionParams: %q; expected %q",
115-
string(rentry.ConnectionParams), realLeaderConnectionParams)
116-
}
117-
},
118-
TermLength: time.Millisecond * 30,
119-
ConnectionParams: []byte(realLeaderConnectionParams),
120-
}
121-
122-
if err := c.Acquire(ctx); err != context.Canceled {
123-
t.Errorf("non-cancel-error: %s", err)
124-
}
125-
if onElectedCalls != 1 {
126-
t.Errorf("unexpected number of OnElected calls: %d", onElectedCalls)
127-
}
128-
}
129-
13022
func TestAcquireTrivialUncontendedFakeClock(t *testing.T) {
13123
t.Parallel()
13224
ctx, cancel := context.WithCancel(context.Background())

0 commit comments

Comments
 (0)