Skip to content

Commit aa66a58

Browse files
authored
Merge branch 'master' into raul/mel-replay-receipt-walking
2 parents d267d9d + b5b730a commit aa66a58

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

util/redisutil/redis_coordinator.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ func (rc *RedisCoordinator) GetPriorities(ctx context.Context) ([]string, error)
138138
// GetLiveliness returns a list of sequencers that have their liveliness set to OK
139139
func (rc *RedisCoordinator) GetLiveliness(ctx context.Context) ([]string, error) {
140140
var livelinessList []string
141-
cursor := uint64(0)
141+
var cursor uint64
142142
for {
143-
keySlice, cursor, err := rc.Client.Scan(ctx, cursor, WANTS_LOCKOUT_KEY_PREFIX+"*", 0).Result()
143+
var keySlice []string
144+
var err error
145+
keySlice, cursor, err = rc.Client.Scan(ctx, cursor, WANTS_LOCKOUT_KEY_PREFIX+"*", 0).Result()
144146
if err != nil {
145147
return []string{}, err
146148
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2021-2022, Offchain Labs, Inc.
2+
// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE.md
3+
4+
package redisutil
5+
6+
import (
7+
"context"
8+
"sort"
9+
"testing"
10+
"time"
11+
)
12+
13+
func TestRedisCoordinatorGetLiveliness(t *testing.T) {
14+
ctx, cancel := context.WithCancel(context.Background())
15+
defer cancel()
16+
17+
redisUrl := CreateTestRedis(ctx, t)
18+
redisCoordinator, err := NewRedisCoordinator(redisUrl, 0)
19+
if err != nil {
20+
t.Fatalf("error creating redis coordinator: %s", err.Error())
21+
}
22+
wantLivelinessList := []string{"a", "b", "c", "d", "e", "f"}
23+
for _, url := range wantLivelinessList {
24+
if _, err = redisCoordinator.Client.Set(ctx, WantsLockoutKeyFor(url), WANTS_LOCKOUT_VAL, time.Minute).Result(); err != nil {
25+
t.Fatalf("error setting liveliness key for: %s err: %s", url, err.Error())
26+
}
27+
}
28+
haveLivelinessList, err := redisCoordinator.GetLiveliness(ctx)
29+
if err != nil {
30+
t.Fatalf("error getting liveliness list: %s", err.Error())
31+
}
32+
sort.Strings(haveLivelinessList)
33+
if len(wantLivelinessList) != len(haveLivelinessList) {
34+
t.Fatalf("liveliness list length mismatch")
35+
}
36+
for i, want := range wantLivelinessList {
37+
if haveLivelinessList[i] != want {
38+
t.Fatalf("liveliness list url mismatch. want: %s have: %s", want, haveLivelinessList[i])
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)