diff --git a/Makefile b/Makefile index fbba1c176e8df8247f208c2fb71fcc51f2c66e5e..1ef59ba3c5182aa82aba4d50530780f2a9f2653f 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 70cf817c85d5290e76b76c9c608568e16a3364c5..921917f976f647eca450308af7f08c4d00410b53 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 5d4dca7bc79c10f0e5de62f01e2ccff68fd2ca29..dcc1a4da59377baf54789c83771ff5ad3f12eee2 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 49a395a9c45a33f25892cc1efc86e263ccf06063..b071c7e437d149eb49aec41da593f858c4c01354 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 ada6de8fc00916699b45eaee1483830a277b9fc9..d738580aad5d66ad4eab81ee934db52b24313825 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.") } }