Skip to content

Commit

Permalink
randomize listen port. makes the tests pass on macos. (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
perbu authored Nov 17, 2023
1 parent 58f1195 commit 51023ac
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions remote/remote_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package remote

import (
"fmt"
"math/rand"
"sync"
"testing"
"time"
Expand All @@ -16,13 +18,14 @@ func init() {
}

func TestSend(t *testing.T) {
const msgs = 10
var (
a = makeRemoteEngine("127.0.0.2:4000")
b = makeRemoteEngine("127.0.0.2:5000")
a = makeRemoteEngine(getRandomLocalhostAddr())
b = makeRemoteEngine(getRandomLocalhostAddr())
wg = sync.WaitGroup{}
)

wg.Add(10) // send 2 messages
wg.Add(msgs) // send msgs messages
pid := a.SpawnFunc(func(c *actor.Context) {
switch msg := c.Message().(type) {
case *TestMessage:
Expand All @@ -31,16 +34,16 @@ func TestSend(t *testing.T) {
}
}, "dfoo")

for i := 0; i < 10; i++ {
for i := 0; i < msgs; i++ {
b.Send(pid, &TestMessage{Data: []byte("foo")})
}
wg.Wait()
}

func TestWithSender(t *testing.T) {
var (
a = makeRemoteEngine("127.0.0.4:4000")
b = makeRemoteEngine("127.0.0.4:5000")
a = makeRemoteEngine(getRandomLocalhostAddr())
b = makeRemoteEngine(getRandomLocalhostAddr())
wg = sync.WaitGroup{}
senderPID = actor.NewPID("a", "b")
)
Expand All @@ -65,8 +68,8 @@ func TestWithSender(t *testing.T) {

func TestRequestResponse(t *testing.T) {
var (
a = makeRemoteEngine("127.0.0.1:4001")
b = makeRemoteEngine("127.0.0.1:5001")
a = makeRemoteEngine(getRandomLocalhostAddr())
b = makeRemoteEngine(getRandomLocalhostAddr())
wg = sync.WaitGroup{}
)

Expand Down Expand Up @@ -96,3 +99,7 @@ func makeRemoteEngine(listenAddr string) *actor.Engine {
e.WithRemote(r)
return e
}

func getRandomLocalhostAddr() string {
return fmt.Sprintf("localhost:%d", rand.Intn(50000)+10000)
}

0 comments on commit 51023ac

Please sign in to comment.