diff --git a/fileTransfer2/connect/wrapper_test.go b/fileTransfer2/connect/wrapper_test.go index ff538756f1aa858746e969fd8cf0a5fdd0ebf763..686580a2a560b713b51e5ade85b1d5e04718f78d 100644 --- a/fileTransfer2/connect/wrapper_test.go +++ b/fileTransfer2/connect/wrapper_test.go @@ -20,6 +20,7 @@ import ( "gitlab.com/xx_network/primitives/netTime" "math" "sync" + "sync/atomic" "testing" "time" ) @@ -113,14 +114,14 @@ func Test_FileTransfer_Smoke(t *testing.T) { // a progress callback that then checks that the file received is correct // when done wg.Add(1) - var called bool + called := uint32(0) timeReceived := make(chan time.Time) go func() { select { case r := <-receiveCbChan2: receiveProgressCB := func(completed bool, received, total uint16, rt ft.ReceivedTransfer, fpt ft.FilePartTracker, err error) { - if completed && !called { + if completed && atomic.CompareAndSwapUint32(&called, 0, 1) { timeReceived <- netTime.Now() receivedFile, err2 := m2.Receive(r.tid) if err2 != nil { diff --git a/fileTransfer2/e2e/wrapper_test.go b/fileTransfer2/e2e/wrapper_test.go index 50490e4a1d00b1159c1b5009f0d92d3b6c874695..92133edc5da3c52e0335ea7081f8948a5096f000 100644 --- a/fileTransfer2/e2e/wrapper_test.go +++ b/fileTransfer2/e2e/wrapper_test.go @@ -20,6 +20,7 @@ import ( "gitlab.com/xx_network/primitives/netTime" "math" "sync" + "sync/atomic" "testing" "time" ) @@ -115,14 +116,14 @@ func Test_FileTransfer_Smoke(t *testing.T) { // a progress callback that then checks that the file received is correct // when done wg.Add(1) - var called bool + called := uint32(0) timeReceived := make(chan time.Time) go func() { select { case r := <-receiveCbChan2: receiveProgressCB := func(completed bool, received, total uint16, rt ft.ReceivedTransfer, fpt ft.FilePartTracker, err error) { - if completed && !called { + if completed && atomic.CompareAndSwapUint32(&called, 0, 1) { timeReceived <- netTime.Now() receivedFile, err2 := m2.Receive(r.tid) if err2 != nil { diff --git a/fileTransfer2/groupChat/wrapper_test.go b/fileTransfer2/groupChat/wrapper_test.go index da36d23dbba52e75f62f5b3f2d327b8b84ad9780..a1bb774bfddefb5d199e58bd4b05d7668188414a 100644 --- a/fileTransfer2/groupChat/wrapper_test.go +++ b/fileTransfer2/groupChat/wrapper_test.go @@ -18,6 +18,7 @@ import ( "gitlab.com/xx_network/primitives/netTime" "math" "sync" + "sync/atomic" "testing" "time" ) @@ -100,14 +101,14 @@ func Test_FileTransfer_Smoke(t *testing.T) { // a progress callback that then checks that the file received is correct // when done wg.Add(1) - var called bool + called := uint32(0) timeReceived := make(chan time.Time) go func() { select { case r := <-receiveCbChan2: receiveProgressCB := func(completed bool, received, total uint16, rt ft.ReceivedTransfer, fpt ft.FilePartTracker, err error) { - if completed && !called { + if completed && atomic.CompareAndSwapUint32(&called, 0, 1) { timeReceived <- netTime.Now() receivedFile, err2 := m2.Receive(r.tid) if err2 != nil { diff --git a/fileTransfer2/manager_test.go b/fileTransfer2/manager_test.go index cda5efc7c86dea530a39f9b683d9e7e1b5ee4b50..d9827a5436d58c3da762ec8396524d6b48ffa1c4 100644 --- a/fileTransfer2/manager_test.go +++ b/fileTransfer2/manager_test.go @@ -19,6 +19,7 @@ import ( "math/rand" "reflect" "sync" + "sync/atomic" "testing" "time" ) @@ -137,7 +138,7 @@ func Test_FileTransfer_Smoke(t *testing.T) { // a progress callback that then checks that the file received is correct // when done wg.Add(1) - var called bool + called := uint32(0) timeReceived := make(chan time.Time) go func() { select { @@ -148,7 +149,7 @@ func Test_FileTransfer_Smoke(t *testing.T) { } receiveProgressCB := func(completed bool, received, total uint16, rt ReceivedTransfer, fpt FilePartTracker, err error) { - if completed && !called { + if completed && atomic.CompareAndSwapUint32(&called, 0, 1) { timeReceived <- netTime.Now() receivedFile, err2 := m2.Receive(tid) if err2 != nil {