Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
ab20037f
Commit
ab20037f
authored
2 years ago
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Fix dummy message tests
parent
e71ddf23
No related branches found
No related tags found
2 merge requests
!510
Release
,
!329
Hotfix/dummy message bindings
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
dummy/manager.go
+37
-16
37 additions, 16 deletions
dummy/manager.go
dummy/manager_test.go
+11
-11
11 additions, 11 deletions
dummy/manager_test.go
dummy/mockCmix_test.go
+1
-1
1 addition, 1 deletion
dummy/mockCmix_test.go
dummy/send_test.go
+3
-2
3 additions, 2 deletions
dummy/send_test.go
with
52 additions
and
30 deletions
dummy/manager.go
+
37
−
16
View file @
ab20037f
...
...
@@ -62,8 +62,21 @@ type Manager struct {
rng
*
fastRNG
.
StreamGenerator
}
// NewManager creates a new dummy Manager with the specified average send delta
// and the range used for generating random durations.
// NewManager creates a Manager object and initialises the
// dummy traffic sending thread. Note that the Manager does not start sending dummy
// traffic until True is passed into Manager.SetStatus. The time duration
// between each sending operation and the amount of messages sent each interval
// are randomly generated values with bounds defined by the
// given parameters below.
//
// Params:
// - maxNumMessages - the upper bound of the random number of messages sent
// each sending cycle.
// - avgSendDeltaMS - the average duration, in milliseconds, to wait
// between sends.
// - randomRangeMS - the upper bound of the interval between sending cycles.
// Sends occur every avgSendDeltaMS +/- a random duration with an
// upper bound of randomRangeMS
func
NewManager
(
maxNumMessages
int
,
avgSendDelta
,
randomRange
time
.
Duration
,
net
*
xxdk
.
Cmix
)
*
Manager
{
...
...
@@ -97,13 +110,19 @@ func (m *Manager) StartDummyTraffic() (stoppable.Stoppable, error) {
return
stop
,
nil
}
// SetStatus sets the state of the dummy traffic send thread, which determines
// if the thread is running or paused. The possible statuses are:
// true = send thread is sending dummy messages
// false = send thread is paused/stopped and not sending dummy messages
// Returns an error if the channel is full.
// Note that this function cannot change the status of the send thread if it has
// yet to be started via StartDummyTraffic or if it has been stopped.
// SetStatus sets the state of the dummy traffic send thread by passing in
// a boolean parameter. There may be a small delay in between this call
// and the status of the sending thread to change accordingly. For example,
// passing False into this call while the sending thread is currently sending messages
// will not cancel nor halt the sending operation, but will pause the thread once that
// operation has completed.
//
// Params:
// - boolean - True: Sending thread is sending dummy messages.
// False: Sending thread is paused/stopped and is not sending dummy messages
// Returns:
// - error - if the DummyTraffic.SetStatus is called too frequently, causing the
// internal status channel to fill.
func
(
m
*
Manager
)
SetStatus
(
status
bool
)
error
{
select
{
case
m
.
statusChan
<-
status
:
...
...
@@ -113,13 +132,15 @@ func (m *Manager) SetStatus(status bool) error {
}
}
// GetStatus returns the current state of the dummy traffic send thread. It has
// the following return values:
// true = send thread is sending dummy messages
// false = send thread is paused/stopped and not sending dummy messages
// Note that this function does not return the status set by SetStatus directly;
// it returns the current status of the send thread, which means any call to
// SetStatus will have a small delay before it is returned by GetStatus.
// GetStatus returns the current state of the dummy traffic sending thread.
// Note that this function does not return the status set by the most recent call to
// SetStatus directly. Instead, this call returns the current status of the sending thread.
// This is due to the small delay that may occur between calling SetStatus and the
// sending thread taking into effect that status change.
//
// Returns:
// - boolean - True: Sending thread is sending dummy messages.
// - False: Sending thread is paused/stopped and is not sending dummy messages.
func
(
m
*
Manager
)
GetStatus
()
bool
{
switch
atomic
.
LoadUint32
(
&
m
.
status
)
{
case
running
:
...
...
This diff is collapsed.
Click to expand it.
dummy/manager_test.go
+
11
−
11
View file @
ab20037f
...
...
@@ -27,7 +27,7 @@ func Test_newManager(t *testing.T) {
}
received
:=
newManager
(
expected
.
maxNumMessages
,
expected
.
avgSendDelta
,
expected
.
randomRange
,
nil
,
nil
,
nil
,
nil
)
expected
.
randomRange
,
nil
,
nil
,
nil
)
if
statusChanLen
!=
cap
(
received
.
statusChan
)
{
t
.
Errorf
(
"Capacity of status channel unexpected."
+
...
...
@@ -118,10 +118,10 @@ func TestManager_SetStatus(t *testing.T) {
go
func
()
{
var
numReceived
int
for
i
:=
0
;
i
<
2
;
i
++
{
for
m
.
net
workManager
.
(
*
testNetworkManager
)
.
GetMsgListLen
()
==
numReceived
{
for
m
.
net
.
(
*
mockCmix
)
.
GetMsgListLen
()
==
numReceived
{
time
.
Sleep
(
5
*
time
.
Millisecond
)
}
numReceived
=
m
.
net
workManager
.
(
*
testNetworkManager
)
.
GetMsgListLen
()
numReceived
=
m
.
net
.
(
*
mockCmix
)
.
GetMsgListLen
()
msgChan
<-
true
}
}()
...
...
@@ -161,7 +161,7 @@ func TestManager_SetStatus(t *testing.T) {
t
.
Errorf
(
"Timed out after %s waiting for messages to be sent."
,
3
*
m
.
avgSendDelta
)
case
<-
msgChan
:
numReceived
+=
m
.
net
workManager
.
(
*
testNetworkManager
)
.
GetMsgListLen
()
numReceived
+=
m
.
net
.
(
*
mockCmix
)
.
GetMsgListLen
()
}
// Setting status to true multiple times does not interrupt sending
...
...
@@ -177,10 +177,10 @@ func TestManager_SetStatus(t *testing.T) {
t
.
Errorf
(
"Timed out after %s waiting for messages to be sent."
,
3
*
m
.
avgSendDelta
)
case
<-
msgChan
:
if
m
.
net
workManager
.
(
*
testNetworkManager
)
.
GetMsgListLen
()
<=
numReceived
{
if
m
.
net
.
(
*
mockCmix
)
.
GetMsgListLen
()
<=
numReceived
{
t
.
Errorf
(
"Failed to receive second send."
+
"
\n
messages on last receive: %d
\n
messages on this receive: %d"
,
numReceived
,
m
.
net
workManager
.
(
*
testNetworkManager
)
.
GetMsgListLen
())
numReceived
,
m
.
net
.
(
*
mockCmix
)
.
GetMsgListLen
())
}
}
...
...
@@ -254,10 +254,10 @@ func TestManager_GetStatus(t *testing.T) {
go
func
()
{
var
numReceived
int
for
i
:=
0
;
i
<
2
;
i
++
{
for
m
.
net
workManager
.
(
*
testNetworkManager
)
.
GetMsgListLen
()
==
numReceived
{
for
m
.
net
.
(
*
mockCmix
)
.
GetMsgListLen
()
==
numReceived
{
time
.
Sleep
(
5
*
time
.
Millisecond
)
}
numReceived
=
m
.
net
workManager
.
(
*
testNetworkManager
)
.
GetMsgListLen
()
numReceived
=
m
.
net
.
(
*
mockCmix
)
.
GetMsgListLen
()
msgChan
<-
true
}
}()
...
...
@@ -292,7 +292,7 @@ func TestManager_GetStatus(t *testing.T) {
t
.
Errorf
(
"Timed out after %s waiting for messages to be sent."
,
3
*
m
.
avgSendDelta
)
case
<-
msgChan
:
numReceived
+=
m
.
net
workManager
.
(
*
testNetworkManager
)
.
GetMsgListLen
()
numReceived
+=
m
.
net
.
(
*
mockCmix
)
.
GetMsgListLen
()
}
// Setting status to true multiple times does not interrupt sending
...
...
@@ -311,10 +311,10 @@ func TestManager_GetStatus(t *testing.T) {
t
.
Errorf
(
"Timed out after %s waiting for messages to be sent."
,
3
*
m
.
avgSendDelta
)
case
<-
msgChan
:
if
m
.
net
workManager
.
(
*
testNetworkManager
)
.
GetMsgListLen
()
<=
numReceived
{
if
m
.
net
.
(
*
mockCmix
)
.
GetMsgListLen
()
<=
numReceived
{
t
.
Errorf
(
"Failed to receive second send."
+
"
\n
messages on last receive: %d
\n
messages on this receive: %d"
,
numReceived
,
m
.
net
workManager
.
(
*
testNetworkManager
)
.
GetMsgListLen
())
numReceived
,
m
.
net
.
(
*
mockCmix
)
.
GetMsgListLen
())
}
}
...
...
This diff is collapsed.
Click to expand it.
dummy/mockCmix_test.go
+
1
−
1
View file @
ab20037f
...
...
@@ -39,7 +39,7 @@ func newMockCmix() cmix.Client {
func
(
m
*
mockCmix
)
Send
(
recipient
*
id
.
ID
,
fingerprint
format
.
Fingerprint
,
service
message
.
Service
,
payload
,
mac
[]
byte
,
cmixParams
cmix
.
CMIXParams
)
(
id
.
Round
,
ephemeral
.
Id
,
error
)
{
m
.
Lock
()
defer
m
.
Unlock
()
m
.
messages
[
*
recipient
]
=
payload
m
.
messages
[
*
recipient
]
=
fingerprint
.
Bytes
()
return
0
,
ephemeral
.
Id
{},
nil
}
...
...
This diff is collapsed.
Click to expand it.
dummy/send_test.go
+
3
−
2
View file @
ab20037f
...
...
@@ -128,9 +128,10 @@ func TestManager_sendMessages(t *testing.T) {
receivedMsg
,
exists
:=
receivedMsgs
[
recipient
]
if
!
exists
{
t
.
Errorf
(
"Failed to receive message from %s: %+v"
,
&
recipient
,
msg
)
}
else
if
!
reflect
.
DeepEqual
(
msg
,
receivedMsg
)
{
}
else
if
!
reflect
.
DeepEqual
(
msg
.
GetKeyFP
()
.
Bytes
(),
receivedMsg
)
{
// In mockCmix.Send, we map recipientId to the passed fingerprint.
t
.
Errorf
(
"Received unexpected message for recipient %s."
+
"
\n
expected: %+v
\n
received: %+v"
,
&
recipient
,
msg
,
receivedMsg
)
"
\n
expected: %+v
\n
received: %+v"
,
&
recipient
,
msg
.
GetKeyFP
()
,
receivedMsg
)
}
}
}
...
...
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