From cd754b15bab68bdd8da3c48ad3a2a99bdab0a11a Mon Sep 17 00:00:00 2001
From: Jono Wenger <jono@elixxir.io>
Date: Thu, 18 May 2023 11:29:01 -0700
Subject: [PATCH] Update Makefile

---
 Makefile               | 10 ++++++++-
 go.mod                 |  2 +-
 go.sum                 |  4 ++--
 worker/manager_test.go | 48 +++++++++++++++++++++---------------------
 worker/thread_test.go  | 32 ++++++++++++++--------------
 5 files changed, 52 insertions(+), 44 deletions(-)

diff --git a/Makefile b/Makefile
index fbba1c17..1ef59ba3 100644
--- a/Makefile
+++ b/Makefile
@@ -36,8 +36,16 @@ worker_binaries:
 
 binaries: binary worker_binaries
 
+wasmException = "vendor/gitlab.com/elixxir/wasm-utils/exception"
+
 wasm_tests:
-	GOOS=js GOARCH=wasm go test -v ./...
+	cp $(wasmException)/throw_js.s $(wasmException)/throw_js.s.bak
+	cp $(wasmException)/throws.go $(wasmException)/throws.go.bak
+	> $(wasmException)/throw_js.s
+	cp $(wasmException)/throws.dev $(wasmException)/throws.go
+	-GOOS=js GOARCH=wasm go test -v ./worker/... -run TestManager_[rR]
+	mv $(wasmException)/throw_js.s.bak $(wasmException)/throw_js.s
+	mv $(wasmException)/throws.go.bak $(wasmException)/throws.go
 
 go_tests:
 	go test ./... -v
diff --git a/go.mod b/go.mod
index 70cf817c..921917f9 100644
--- a/go.mod
+++ b/go.mod
@@ -11,7 +11,7 @@ require (
 	gitlab.com/elixxir/client/v4 v4.6.3
 	gitlab.com/elixxir/crypto v0.0.7-0.20230413162806-a99ec4bfea32
 	gitlab.com/elixxir/primitives v0.0.3-0.20230214180039-9a25e2d3969c
-	gitlab.com/elixxir/wasm-utils v0.0.0-20230517220713-7418aa4da283
+	gitlab.com/elixxir/wasm-utils v0.0.0-20230518173031-b91665c79b0a
 	gitlab.com/xx_network/crypto v0.0.5-0.20230214003943-8a09396e95dd
 	gitlab.com/xx_network/primitives v0.0.4-0.20230310205521-c440e68e34c4
 	golang.org/x/crypto v0.5.0
diff --git a/go.sum b/go.sum
index 5d4dca7b..dcc1a4da 100644
--- a/go.sum
+++ b/go.sum
@@ -408,8 +408,8 @@ gitlab.com/elixxir/ekv v0.2.1 h1:dtwbt6KmAXG2Tik5d60iDz2fLhoFBgWwST03p7T+9Is=
 gitlab.com/elixxir/ekv v0.2.1/go.mod h1:USLD7xeDnuZEavygdrgzNEwZXeLQJK/w1a+htpN+JEU=
 gitlab.com/elixxir/primitives v0.0.3-0.20230214180039-9a25e2d3969c h1:muG8ff95woeVVwQoJHCEclxBFB22lc7EixPylEkYDRU=
 gitlab.com/elixxir/primitives v0.0.3-0.20230214180039-9a25e2d3969c/go.mod h1:phun4PLkHJA6wcL4JIhhxZztrmCyJHWPNppBP3DUD2Y=
-gitlab.com/elixxir/wasm-utils v0.0.0-20230517220713-7418aa4da283 h1:6hcMS/cVSfx8z8NYvGk4p3VakZutfcSxWnP/hz3owTQ=
-gitlab.com/elixxir/wasm-utils v0.0.0-20230517220713-7418aa4da283/go.mod h1:wB7Vh/7LWUm8wYRBSd+6lxfpk4CnDaHTkLCIVKfL2TA=
+gitlab.com/elixxir/wasm-utils v0.0.0-20230518173031-b91665c79b0a h1:OU1YZwVbrkaGBD4bH+V/vgLM2o9QMi8Gct//OckA6kc=
+gitlab.com/elixxir/wasm-utils v0.0.0-20230518173031-b91665c79b0a/go.mod h1:wB7Vh/7LWUm8wYRBSd+6lxfpk4CnDaHTkLCIVKfL2TA=
 gitlab.com/xx_network/comms v0.0.4-0.20230214180029-5387fb85736d h1:AZf2h0fxyO1KxhZPP9//jG3Swb2BcuKbxtNXJgooLss=
 gitlab.com/xx_network/comms v0.0.4-0.20230214180029-5387fb85736d/go.mod h1:8cwPyH6G8C4qf/U5KDghn1ksOh79MrNqthjKDrfvbXY=
 gitlab.com/xx_network/crypto v0.0.5-0.20230214003943-8a09396e95dd h1:IleH6U5D/c2zF6YL/z3cBKqBPnI5ApNMCtU7ia4t228=
diff --git a/worker/manager_test.go b/worker/manager_test.go
index 49a395a9..b071c7e4 100644
--- a/worker/manager_test.go
+++ b/worker/manager_test.go
@@ -21,7 +21,7 @@ func TestManager_processReceivedMessage(t *testing.T) {
 	m := &Manager{callbacks: make(map[Tag]map[uint64]ReceptionCallback)}
 
 	msg := Message{Tag: readyTag, ID: 5}
-	cbChan := make(chan struct{})
+	cbChan := make(chan struct{}, 1)
 	cb := func([]byte) { cbChan <- struct{}{} }
 	m.callbacks[msg.Tag] = map[uint64]ReceptionCallback{msg.ID: cb}
 
@@ -31,16 +31,16 @@ func TestManager_processReceivedMessage(t *testing.T) {
 	}
 
 	go func() {
-		select {
-		case <-cbChan:
-		case <-time.After(10 * time.Millisecond):
-			t.Error("Timed out waiting for callback to be called.")
+		err = m.processReceivedMessage(data)
+		if err != nil {
+			t.Errorf("Failed to receive message: %+v", err)
 		}
 	}()
 
-	err = m.processReceivedMessage(data)
-	if err != nil {
-		t.Errorf("Failed to receive message: %+v", err)
+	select {
+	case <-cbChan:
+	case <-time.After(10 * time.Millisecond):
+		t.Error("Timed out waiting for callback to be called.")
 	}
 }
 
@@ -97,7 +97,7 @@ func TestManager_RegisterCallback(t *testing.T) {
 	m := &Manager{callbacks: make(map[Tag]map[uint64]ReceptionCallback)}
 
 	msg := Message{Tag: readyTag, ID: initID}
-	cbChan := make(chan struct{})
+	cbChan := make(chan struct{}, 1)
 	cb := func([]byte) { cbChan <- struct{}{} }
 	m.RegisterCallback(msg.Tag, cb)
 
@@ -107,16 +107,16 @@ func TestManager_RegisterCallback(t *testing.T) {
 	}
 
 	go func() {
-		select {
-		case <-cbChan:
-		case <-time.After(10 * time.Millisecond):
-			t.Error("Timed out waiting for callback to be called.")
+		err = m.processReceivedMessage(data)
+		if err != nil {
+			t.Errorf("Failed to receive message: %+v", err)
 		}
 	}()
 
-	err = m.processReceivedMessage(data)
-	if err != nil {
-		t.Errorf("Failed to receive message: %+v", err)
+	select {
+	case <-cbChan:
+	case <-time.After(10 * time.Millisecond):
+		t.Error("Timed out waiting for callback to be called.")
 	}
 }
 
@@ -129,7 +129,7 @@ func TestManager_registerReplyCallback(t *testing.T) {
 	}
 
 	msg := Message{Tag: readyTag, ID: 5}
-	cbChan := make(chan struct{})
+	cbChan := make(chan struct{}, 1)
 	cb := func([]byte) { cbChan <- struct{}{} }
 	m.registerReplyCallback(msg.Tag, cb)
 	m.callbacks[msg.Tag] = map[uint64]ReceptionCallback{msg.ID: cb}
@@ -140,16 +140,16 @@ func TestManager_registerReplyCallback(t *testing.T) {
 	}
 
 	go func() {
-		select {
-		case <-cbChan:
-		case <-time.After(10 * time.Millisecond):
-			t.Error("Timed out waiting for callback to be called.")
+		err = m.processReceivedMessage(data)
+		if err != nil {
+			t.Errorf("Failed to receive message: %+v", err)
 		}
 	}()
 
-	err = m.processReceivedMessage(data)
-	if err != nil {
-		t.Errorf("Failed to receive message: %+v", err)
+	select {
+	case <-cbChan:
+	case <-time.After(10 * time.Millisecond):
+		t.Error("Timed out waiting for callback to be called.")
 	}
 }
 
diff --git a/worker/thread_test.go b/worker/thread_test.go
index ada6de8f..d738580a 100644
--- a/worker/thread_test.go
+++ b/worker/thread_test.go
@@ -20,7 +20,7 @@ func TestThreadManager_processReceivedMessage(t *testing.T) {
 	tm := &ThreadManager{callbacks: make(map[Tag]ThreadReceptionCallback)}
 
 	msg := Message{Tag: readyTag, ID: 5}
-	cbChan := make(chan struct{})
+	cbChan := make(chan struct{}, 1)
 	cb := func([]byte) ([]byte, error) { cbChan <- struct{}{}; return nil, nil }
 	tm.callbacks[msg.Tag] = cb
 
@@ -30,16 +30,16 @@ func TestThreadManager_processReceivedMessage(t *testing.T) {
 	}
 
 	go func() {
-		select {
-		case <-cbChan:
-		case <-time.After(10 * time.Millisecond):
-			t.Error("Timed out waiting for callback to be called.")
+		err = tm.processReceivedMessage(data)
+		if err != nil {
+			t.Errorf("Failed to receive message: %+v", err)
 		}
 	}()
 
-	err = tm.processReceivedMessage(data)
-	if err != nil {
-		t.Errorf("Failed to receive message: %+v", err)
+	select {
+	case <-cbChan:
+	case <-time.After(10 * time.Millisecond):
+		t.Error("Timed out waiting for callback to be called.")
 	}
 }
 
@@ -49,7 +49,7 @@ func TestThreadManager_RegisterCallback(t *testing.T) {
 	tm := &ThreadManager{callbacks: make(map[Tag]ThreadReceptionCallback)}
 
 	msg := Message{Tag: readyTag, ID: 5}
-	cbChan := make(chan struct{})
+	cbChan := make(chan struct{}, 1)
 	cb := func([]byte) ([]byte, error) { cbChan <- struct{}{}; return nil, nil }
 	tm.RegisterCallback(msg.Tag, cb)
 
@@ -59,15 +59,15 @@ func TestThreadManager_RegisterCallback(t *testing.T) {
 	}
 
 	go func() {
-		select {
-		case <-cbChan:
-		case <-time.After(10 * time.Millisecond):
-			t.Error("Timed out waiting for callback to be called.")
+		err = tm.processReceivedMessage(data)
+		if err != nil {
+			t.Errorf("Failed to receive message: %+v", err)
 		}
 	}()
 
-	err = tm.processReceivedMessage(data)
-	if err != nil {
-		t.Errorf("Failed to receive message: %+v", err)
+	select {
+	case <-cbChan:
+	case <-time.After(10 * time.Millisecond):
+		t.Error("Timed out waiting for callback to be called.")
 	}
 }
-- 
GitLab