Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
comms
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
comms
Commits
3b95afbc
Commit
3b95afbc
authored
Sep 8, 2021
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Fix racy test
parent
6441cd9a
No related branches found
No related tags found
3 merge requests
!58
Revert "Modify waiting lock"
,
!9
Release
,
!6
Fix racy test
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
network/instance_test.go
+11
-8
11 additions, 8 deletions
network/instance_test.go
with
11 additions
and
8 deletions
network/instance_test.go
+
11
−
8
View file @
3b95afbc
...
...
@@ -19,6 +19,7 @@ import (
"gitlab.com/xx_network/primitives/ndf"
"reflect"
"strings"
"sync/atomic"
"testing"
"time"
)
...
...
@@ -885,15 +886,15 @@ func TestInstance_NodeEventModel(t *testing.T) {
}
// Set up channels that count number of items they receive
counter
:=
0
counter
:=
uint32
(
0
)
go
func
()
{
for
range
addNode
{
counter
+=
1
atomic
.
AddUint32
(
&
counter
,
1
)
}
}()
go
func
()
{
for
range
addGateway
{
counter
+=
1
atomic
.
AddUint32
(
&
counter
,
1
)
}
}()
...
...
@@ -917,12 +918,14 @@ func TestInstance_NodeEventModel(t *testing.T) {
// Verify channels received the correct amount of information
timeout
:=
5
for
{
if
counter
==
len
(
newNdf
.
Nodes
)
+
len
(
newNdf
.
Gateways
)
{
counterVal
:=
atomic
.
LoadUint32
(
&
counter
)
totalNodeGateways
:=
uint32
(
len
(
newNdf
.
Nodes
)
+
len
(
newNdf
.
Gateways
))
if
counterVal
==
totalNodeGateways
{
break
}
else
{
timeout
-=
1
if
timeout
==
0
{
t
.
Errorf
(
"Unable to properly add nodes and gateways! Got %d"
,
counter
)
t
.
Errorf
(
"Unable to properly add nodes and gateways! Got %d"
,
atomic
.
LoadUint32
(
&
counter
)
)
return
}
}
...
...
@@ -948,12 +951,12 @@ func TestInstance_NodeEventModel(t *testing.T) {
// Set up channels that reduce counter by the number of items they receive
go
func
()
{
for
range
removeNode
{
counter
-=
1
atomic
.
AddUint32
(
&
counter
,
^
uint32
(
0
))
// decrement
counter
}
}()
go
func
()
{
for
range
removeGateway
{
counter
-=
1
atomic
.
AddUint32
(
&
counter
,
^
uint32
(
0
))
// decrement
counter
}
}()
...
...
@@ -966,7 +969,7 @@ func TestInstance_NodeEventModel(t *testing.T) {
// Verify channels received the correct amount of information
timeout
=
5
for
{
if
counter
==
0
{
if
atomic
.
LoadUint32
(
&
counter
)
==
0
{
break
}
else
{
timeout
-=
1
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment