Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattayes committed Nov 13, 2023
1 parent 95ac4e5 commit 6027094
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 116 deletions.
17 changes: 1 addition & 16 deletions bench/testserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/lytics/grid/v3"
"github.com/lytics/grid/v3/testetcd"
clientv3 "go.etcd.io/etcd/client/v3"
)

const mailboxName = "pingpong-leader"
Expand Down Expand Up @@ -73,21 +72,7 @@ func runPingPongGrid(t testing.TB) (*grid.Server, *grid.Client) {
namespace := fmt.Sprintf("bench-pingpong-namespace-%d", rand.Int63())
logger := log.New(os.Stderr, namespace+": ", log.LstdFlags|log.Lshortfile)

embed := testetcd.NewEmbedded(t)

cfg := clientv3.Config{
Endpoints: embed.Endpoints(),
DialTimeout: time.Second,
}
etcd, err := clientv3.New(cfg)
if err != nil {
t.Fatalf("creating etcd client: %v", err)
}
t.Cleanup(func() {
if err := etcd.Close(); err != nil {
t.Fatalf("closing etcd client: %v", err)
}
})
etcd := testetcd.StartAndConnect(t)

server, err := grid.NewServer(etcd, grid.ServerCfg{Namespace: namespace})
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion client_health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
)

func TestClientCheck(t *testing.T) {
t.Parallel()
_, server, client := bootstrapClientTest(t)

peer := server.registry.Registry()
Expand Down
30 changes: 3 additions & 27 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ func (a *echoActor) Act(c context.Context) {
}
}
func TestNewClient(t *testing.T) {
t.Parallel()
embed := testetcd.NewEmbedded(t)
etcd := testetcd.StartAndConnect(t, embed.Endpoints())

etcd := testetcd.StartAndConnect(t)
client, err := NewClient(etcd, ClientCfg{Namespace: newNamespace(t)})
if err != nil {
t.Fatal(err)
Expand All @@ -99,20 +96,14 @@ func TestNewClient(t *testing.T) {
}

func TestNewClientWithNilEtcd(t *testing.T) {
t.Parallel()
_, err := NewClient(nil, ClientCfg{Namespace: newNamespace(t)})
if err == nil {
t.Fatal("expected error")
}
}

func TestClientClose(t *testing.T) {
t.Parallel()
// Start etcd.
embed := testetcd.NewEmbedded(t)
etcd := testetcd.StartAndConnect(t, embed.Endpoints())

// Create client.
etcd := testetcd.StartAndConnect(t)
client, err := NewClient(etcd, ClientCfg{Namespace: newNamespace(t)})
if err != nil {
t.Fatal(err)
Expand All @@ -129,7 +120,6 @@ func TestClientClose(t *testing.T) {
}

func TestClientRequestWithUnregisteredMailbox(t *testing.T) {
t.Parallel()

// Bootstrap.
_, _, client := bootstrapClientTest(t)
Expand All @@ -155,7 +145,6 @@ func TestClientRequestWithUnregisteredMailbox(t *testing.T) {
}

func TestClientRequestWithUnknownMailbox(t *testing.T) {
t.Parallel()
const timeout = 3 * time.Second

// Bootstrap.
Expand Down Expand Up @@ -194,7 +183,6 @@ func TestClientRequestWithUnknownMailbox(t *testing.T) {
}

func TestClientBroadcast(t *testing.T) {
t.Parallel()
ctx := context.Background()
const timeout = 3 * time.Second
_, server, client := bootstrapClientTest(t)
Expand Down Expand Up @@ -325,7 +313,6 @@ func TestClientBroadcast(t *testing.T) {
}

func TestClientWithRunningReceiver(t *testing.T) {
t.Parallel()
const timeout = 3 * time.Second
expected := &EchoMsg{Msg: "testing 1, 2, 3"}

Expand Down Expand Up @@ -396,7 +383,6 @@ func TestClientWithRunningReceiver(t *testing.T) {
}

func TestClientWithErrConnectionIsUnregistered(t *testing.T) {
t.Parallel()
const timeout = 3 * time.Second
expected := &EchoMsg{Msg: "testing 1, 2, 3"}

Expand Down Expand Up @@ -477,7 +463,6 @@ func TestClientWithErrConnectionIsUnregistered(t *testing.T) {
}

func TestClientWithBusyReceiver(t *testing.T) {
t.Parallel()
const timeout = 3 * time.Second
expected := &EchoMsg{Msg: "testing 1, 2, 3"}

Expand Down Expand Up @@ -536,7 +521,6 @@ func TestClientWithBusyReceiver(t *testing.T) {
}

func TestClientStats(t *testing.T) {
t.Parallel()
cs := newClientStats()
cs.Inc(numGetWireClient)
cs.Inc(numDeleteAddress)
Expand All @@ -555,7 +539,6 @@ func TestClientStats(t *testing.T) {
}

func TestNilClientStats(t *testing.T) {
t.Parallel()
defer func() {
if r := recover(); r != nil {
t.Fatal("expected no panic")
Expand All @@ -567,17 +550,10 @@ func TestNilClientStats(t *testing.T) {

func bootstrapClientTest(t testing.TB) (*clientv3.Client, *Server, *Client) {
t.Helper()
// Namespace for test.
namespace := newNamespace(t)

// Start etcd.
embed := testetcd.NewEmbedded(t)
etcd := testetcd.StartAndConnect(t, embed.Endpoints())

// Logger for actors.
etcd := testetcd.StartAndConnect(t)
logger := log.New(os.Stderr, namespace+": ", log.LstdFlags)

// Create the server.
server, err := NewServer(etcd, ServerCfg{Namespace: namespace, Logger: logger})
require.NoError(t, err)

Expand Down
5 changes: 1 addition & 4 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func (a *contextActor) Context() context.Context {
}

func TestContextError(t *testing.T) {
t.Parallel()
// Create a context that is not valid to use
// with the grid context methods. The context
// is not valid because it does not contain
Expand Down Expand Up @@ -63,11 +62,9 @@ func TestContextError(t *testing.T) {
}

func TestValidContext(t *testing.T) {
t.Parallel()
const timeout = 2 * time.Second

embed := testetcd.NewEmbedded(t)
etcd := testetcd.StartAndConnect(t, embed.Endpoints())
etcd := testetcd.StartAndConnect(t)

a := &contextActor{started: make(chan bool)}

Expand Down
10 changes: 1 addition & 9 deletions mailbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ import (
)

func TestNewMailboxRegistry(t *testing.T) {
t.Parallel()
m := newMailboxRegistry()
require.NotZero(t, m)
assert.NotZero(t, m.r)
}

func TestMailboxRegistryGetSetDeleteSize(t *testing.T) {
t.Parallel()

const n1 = "n1"
const n2 = "n2"
Expand Down Expand Up @@ -98,12 +96,10 @@ func TestMailboxRegistryGetSetDeleteSize(t *testing.T) {
}

func TestMailboxRegistryR(t *testing.T) {
t.Parallel()

for _, n := range []int{0, 1, 2} {
n := n
t.Run(strconv.Itoa(n), func(t *testing.T) {
t.Parallel()

r := newMailboxRegistry()
ms := r.R()
Expand Down Expand Up @@ -133,7 +129,6 @@ func TestMailboxRegistryR(t *testing.T) {
// is safe to use concurrently. It relies on the -race test flag
// to detect races: the test itself has no assertions.
func TestMailboxRegistryConcurrent(t *testing.T) {
t.Parallel()

// NOTE (2022-01) (mh): Only doing one combo for sanity.
// Could test performance/correctness at higher contention.
Expand All @@ -149,7 +144,6 @@ func TestMailboxRegistryConcurrent(t *testing.T) {
for _, numKeys := range numKeysSet {
numKeys := numKeys
t.Run(fmt.Sprintf("%v-%v", numWorkers, numKeys), func(t *testing.T) {
t.Parallel()

r := newMailboxRegistry()

Expand Down Expand Up @@ -194,9 +188,7 @@ func TestMailboxRegistryConcurrent(t *testing.T) {
}

func TestMailboxClose(t *testing.T) {
t.Parallel()
embed := testetcd.NewEmbedded(t)
etcd := testetcd.StartAndConnect(t, embed.Endpoints())
etcd := testetcd.StartAndConnect(t)

s, err := NewServer(etcd, ServerCfg{Namespace: newNamespace(t)})
require.NoError(t, err)
Expand Down
9 changes: 2 additions & 7 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ import (
)

func TestQuery(t *testing.T) {
t.Parallel()
const (
nrPeers = 2
backoff = 10 * time.Second
timeout = 1 * time.Second
)

namespace := newNamespace(t)

embed := testetcd.NewEmbedded(t)
etcd := testetcd.StartAndConnect(t, embed.Endpoints())
etcd := testetcd.StartAndConnect(t)

client, err := NewClient(etcd, ClientCfg{Namespace: namespace})
if err != nil {
Expand Down Expand Up @@ -73,16 +70,14 @@ func TestQuery(t *testing.T) {
}

func TestQueryWatch(t *testing.T) {
t.Parallel()
const (
nrPeers = 2
backoff = 10 * time.Second
timeout = 1 * time.Second
)

namespace := newNamespace(t)
embed := testetcd.NewEmbedded(t)
etcd := testetcd.StartAndConnect(t, embed.Endpoints())
etcd := testetcd.StartAndConnect(t)

client, err := NewClient(etcd, ClientCfg{Namespace: namespace})
if err != nil {
Expand Down
18 changes: 1 addition & 17 deletions registry/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const (
)

func TestInitialLeaseID(t *testing.T) {
t.Parallel()
_, r, _ := bootstrap(t, dontStart)

if r.leaseID != -1 {
Expand All @@ -30,7 +29,6 @@ func TestInitialLeaseID(t *testing.T) {
}

func TestStartStop(t *testing.T) {
t.Parallel()
_, r, _ := bootstrap(t, start)

err := r.Stop()
Expand All @@ -45,7 +43,6 @@ func TestStartStop(t *testing.T) {
}

func TestStartStopWaitForLeaseToExpireBetween(t *testing.T) {
t.Parallel()
client, r, addr := bootstrap(t, start)

// this should remove the lease which should clean up the registry lock on the address
Expand Down Expand Up @@ -87,7 +84,6 @@ func TestStartStopWaitForLeaseToExpireBetween(t *testing.T) {
}

func TestWaitForLeaseThatNeverExpires(t *testing.T) {
t.Parallel()

client, _, addr := bootstrap(t, dontStart)

Expand Down Expand Up @@ -133,7 +129,6 @@ func TestWaitForLeaseThatNeverExpires(t *testing.T) {
}

func TestWaitForLeaseThatDoesExpires(t *testing.T) {
t.Parallel()

start := false
client, _, addr := bootstrap(t, start)
Expand Down Expand Up @@ -186,7 +181,6 @@ func TestWaitForLeaseThatDoesExpires(t *testing.T) {
}

func TestRegister(t *testing.T) {
t.Parallel()
client, r, _ := bootstrap(t, start)

ctx, cancel := timeoutContext()
Expand Down Expand Up @@ -216,7 +210,6 @@ func TestRegister(t *testing.T) {
}

func TestDeregistration(t *testing.T) {
t.Parallel()
client, r, _ := bootstrap(t, start)

ctx, cancel := timeoutContext()
Expand Down Expand Up @@ -265,7 +258,6 @@ func TestDeregistration(t *testing.T) {
}

func TestRegisterDeregisterWhileNotStarted(t *testing.T) {
t.Parallel()
_, r, _ := bootstrap(t, dontStart)

ctx, cancel := timeoutContext()
Expand All @@ -284,7 +276,6 @@ func TestRegisterDeregisterWhileNotStarted(t *testing.T) {
}

func TestRegisterTwiceNotAllowed(t *testing.T) {
t.Parallel()
_, r, _ := bootstrap(t, start)

for i := 0; i < 2; i++ {
Expand All @@ -298,7 +289,6 @@ func TestRegisterTwiceNotAllowed(t *testing.T) {
}

func TestStop(t *testing.T) {
t.Parallel()
client, r, _ := bootstrap(t, start)

ctx, cancel := timeoutContext()
Expand All @@ -321,7 +311,6 @@ func TestStop(t *testing.T) {
}

func TestFindRegistration(t *testing.T) {
t.Parallel()
_, r, _ := bootstrap(t, start)

ctx, cancel := timeoutContext()
Expand Down Expand Up @@ -350,7 +339,6 @@ func TestFindRegistration(t *testing.T) {
}

func TestFindRegistrations(t *testing.T) {
t.Parallel()
_, r, _ := bootstrap(t, start)

ctx, cancel := timeoutContext()
Expand Down Expand Up @@ -392,7 +380,6 @@ func TestFindRegistrations(t *testing.T) {
}

func TestKeepAlive(t *testing.T) {
t.Parallel()
_, r, addr := bootstrap(t, dontStart)

// Change the minimum for sake of testing quickly.
Expand All @@ -418,7 +405,6 @@ func TestKeepAlive(t *testing.T) {
}

func TestWatch(t *testing.T) {
t.Parallel()
_, r, addr := bootstrap(t, dontStart)

// Change the minimum for sake of testing quickly.
Expand Down Expand Up @@ -530,7 +516,6 @@ func TestWatch(t *testing.T) {
}

func TestWatchEventString(t *testing.T) {
t.Parallel()
we := &WatchEvent{
Key: "foo",
Type: Create,
Expand Down Expand Up @@ -565,8 +550,7 @@ func TestWatchEventString(t *testing.T) {

func bootstrap(t testing.TB, shouldStart bool) (*etcdv3.Client, *Registry, *net.TCPAddr) {
t.Helper()
embed := testetcd.NewEmbedded(t)
client := testetcd.StartAndConnect(t, embed.Endpoints())
client := testetcd.StartAndConnect(t)

addr := &net.TCPAddr{
IP: []byte("localhost"),
Expand Down
Loading

0 comments on commit 6027094

Please sign in to comment.