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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
c9e22d7c
Commit
c9e22d7c
authored
Feb 18, 2021
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Fix testing issues and clean up code
parent
597afd47
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
api/messages.go
+0
-9
0 additions, 9 deletions
api/messages.go
api/messages_test.go
+75
-76
75 additions, 76 deletions
api/messages_test.go
api/utilsInterfaces_test.go
+0
-3
0 additions, 3 deletions
api/utilsInterfaces_test.go
api/utils_test.go
+5
-7
5 additions, 7 deletions
api/utils_test.go
with
80 additions
and
95 deletions
api/messages.go
+
0
−
9
View file @
c9e22d7c
...
@@ -7,7 +7,6 @@
...
@@ -7,7 +7,6 @@
package
api
package
api
import
(
import
(
"fmt"
jww
"github.com/spf13/jwalterweatherman"
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/globals"
"gitlab.com/elixxir/client/globals"
"gitlab.com/elixxir/client/network/gateway"
"gitlab.com/elixxir/client/network/gateway"
...
@@ -92,7 +91,6 @@ func (c *Client) getRoundResults(roundList []id.Round, timeout time.Duration,
...
@@ -92,7 +91,6 @@ func (c *Client) getRoundResults(roundList []id.Round, timeout time.Duration,
roundsResults
[
rnd
]
=
Succeeded
roundsResults
[
rnd
]
=
Succeeded
}
else
if
states
.
Round
(
roundInfo
.
State
)
==
states
.
FAILED
{
}
else
if
states
.
Round
(
roundInfo
.
State
)
==
states
.
FAILED
{
roundsResults
[
rnd
]
=
Failed
roundsResults
[
rnd
]
=
Failed
fmt
.
Printf
(
"Round %d considered %v
\n
"
,
roundInfo
.
ID
,
roundInfo
.
State
)
allRoundsSucceeded
=
false
allRoundsSucceeded
=
false
}
else
{
}
else
{
// If in progress, add a channel monitoring its status
// If in progress, add a channel monitoring its status
...
@@ -128,11 +126,9 @@ func (c *Client) getRoundResults(roundList []id.Round, timeout time.Duration,
...
@@ -128,11 +126,9 @@ func (c *Client) getRoundResults(roundList []id.Round, timeout time.Duration,
// Create the results timer
// Create the results timer
timer
:=
time
.
NewTimer
(
timeout
)
timer
:=
time
.
NewTimer
(
timeout
)
for
{
for
{
fmt
.
Printf
(
"looping at most: %v
\n
"
,
numResults
)
// If we know about all rounds, return
// If we know about all rounds, return
if
numResults
==
0
{
if
numResults
==
0
{
fmt
.
Printf
(
"passing to report the following: %v
\n
"
,
allRoundsSucceeded
)
roundCallback
.
Report
(
allRoundsSucceeded
,
false
,
roundsResults
)
roundCallback
.
Report
(
allRoundsSucceeded
,
false
,
roundsResults
)
return
return
}
}
...
@@ -140,11 +136,9 @@ func (c *Client) getRoundResults(roundList []id.Round, timeout time.Duration,
...
@@ -140,11 +136,9 @@ func (c *Client) getRoundResults(roundList []id.Round, timeout time.Duration,
// Wait for info about rounds or the timeout to occur
// Wait for info about rounds or the timeout to occur
select
{
select
{
case
<-
timer
.
C
:
case
<-
timer
.
C
:
fmt
.
Printf
(
"timed out
\n
"
)
roundCallback
.
Report
(
false
,
true
,
roundsResults
)
roundCallback
.
Report
(
false
,
true
,
roundsResults
)
return
return
case
roundReport
:=
<-
sendResults
:
case
roundReport
:=
<-
sendResults
:
fmt
.
Printf
(
"roundReport: %v
\n
"
,
roundReport
)
numResults
--
numResults
--
// Skip if the round is nil (unknown from historical rounds)
// Skip if the round is nil (unknown from historical rounds)
// they default to timed out, so correct behavior is preserved
// they default to timed out, so correct behavior is preserved
...
@@ -154,12 +148,10 @@ func (c *Client) getRoundResults(roundList []id.Round, timeout time.Duration,
...
@@ -154,12 +148,10 @@ func (c *Client) getRoundResults(roundList []id.Round, timeout time.Duration,
// If available, denote the result
// If available, denote the result
roundId
:=
id
.
Round
(
roundReport
.
RoundInfo
.
ID
)
roundId
:=
id
.
Round
(
roundReport
.
RoundInfo
.
ID
)
if
states
.
Round
(
roundReport
.
RoundInfo
.
State
)
==
states
.
COMPLETED
{
if
states
.
Round
(
roundReport
.
RoundInfo
.
State
)
==
states
.
COMPLETED
{
fmt
.
Printf
(
"round %d marked successful
\n
"
,
roundId
)
roundsResults
[
roundId
]
=
Succeeded
roundsResults
[
roundId
]
=
Succeeded
}
else
{
}
else
{
roundsResults
[
roundId
]
=
Failed
roundsResults
[
roundId
]
=
Failed
allRoundsSucceeded
=
false
allRoundsSucceeded
=
false
fmt
.
Printf
(
"Round [unknown] considered [failed]
\n
"
)
}
}
}
}
...
@@ -197,7 +189,6 @@ func (c *Client) getHistoricalRounds(msg *pb.HistoricalRounds,
...
@@ -197,7 +189,6 @@ func (c *Client) getHistoricalRounds(msg *pb.HistoricalRounds,
// Process historical rounds, sending back to the caller thread
// Process historical rounds, sending back to the caller thread
for
_
,
ri
:=
range
resp
.
Rounds
{
for
_
,
ri
:=
range
resp
.
Rounds
{
fmt
.
Printf
(
"received rounds from gateway: %v
\n
"
,
ri
)
sendResults
<-
ds
.
EventReturn
{
sendResults
<-
ds
.
EventReturn
{
ri
,
ri
,
false
,
false
,
...
...
This diff is collapsed.
Click to expand it.
api/messages_test.go
+
75
−
76
View file @
c9e22d7c
...
@@ -11,26 +11,12 @@ import (
...
@@ -11,26 +11,12 @@ import (
ds
"gitlab.com/elixxir/comms/network/dataStructures"
ds
"gitlab.com/elixxir/comms/network/dataStructures"
"gitlab.com/elixxir/primitives/states"
"gitlab.com/elixxir/primitives/states"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id"
"os"
"testing"
"testing"
"time"
"time"
)
)
const
numRounds
=
10
const
numRounds
=
10
var
testClient
*
Client
func
TestMain
(
m
*
testing
.
M
)
{
var
err
error
testClient
,
err
=
newTestingClient
(
m
)
t
:=
testing
.
T
{}
if
err
!=
nil
{
t
.
Errorf
(
"Failed in setup: %v"
,
err
)
}
os
.
Exit
(
m
.
Run
())
}
// Happy path
// Happy path
func
TestClient_GetRoundResults
(
t
*
testing
.
T
)
{
func
TestClient_GetRoundResults
(
t
*
testing
.
T
)
{
// Populate a round list to request
// Populate a round list to request
...
@@ -51,13 +37,17 @@ func TestClient_GetRoundResults(t *testing.T) {
...
@@ -51,13 +37,17 @@ func TestClient_GetRoundResults(t *testing.T) {
}
}
}
}
// Create a new copy of the test client for this test
//// Create a new copy of the test client for this test
client
:=
&
Client
{}
client
,
err
:=
newTestingClient
(
t
)
*
client
=
*
testClient
if
err
!=
nil
{
t
.
Errorf
(
"Failed in setup: %v"
,
err
)
}
// Call the round results
// Call the round results
receivedRCB
:=
NewMockRoundCB
()
receivedRCB
:=
NewMockRoundCB
()
err
:
=
client
.
getRoundResults
(
roundList
,
time
.
Duration
(
10
)
*
time
.
Millisecond
,
err
=
client
.
getRoundResults
(
roundList
,
time
.
Duration
(
10
)
*
time
.
Millisecond
,
receivedRCB
,
sendResults
,
NewNoHistoricalRoundsComm
())
receivedRCB
,
sendResults
,
NewNoHistoricalRoundsComm
())
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Error in happy path: %v"
,
err
)
t
.
Errorf
(
"Error in happy path: %v"
,
err
)
...
@@ -100,23 +90,21 @@ func TestClient_GetRoundResults_FailedRounds(t *testing.T) {
...
@@ -100,23 +90,21 @@ func TestClient_GetRoundResults_FailedRounds(t *testing.T) {
}
}
if
i
==
numRounds
-
2
{
if
i
==
numRounds
-
2
{
result
.
RoundInfo
.
State
=
uint32
(
states
.
FAILED
)
result
.
RoundInfo
.
State
=
uint32
(
states
.
FAILED
)
sendResults
<-
result
}
else
if
i
==
numRounds
-
1
{
result
.
TimedOut
=
true
sendResults
<-
result
}
else
{
sendResults
<-
result
}
}
sendResults
<-
result
}
}
// Create a new copy of the test client for this test
//// Create a new copy of the test client for this test
client
:=
&
Client
{}
client
,
err
:=
newTestingClient
(
t
)
*
client
=
*
testClient
if
err
!=
nil
{
t
.
Errorf
(
"Failed in setup: %v"
,
err
)
}
// Call the round results
// Call the round results
receivedRCB
:=
NewMockRoundCB
()
receivedRCB
:=
NewMockRoundCB
()
err
:
=
client
.
getRoundResults
(
roundList
,
time
.
Duration
(
10
)
*
time
.
Millisecond
,
err
=
client
.
getRoundResults
(
roundList
,
time
.
Duration
(
10
)
*
time
.
Millisecond
,
receivedRCB
,
sendResults
,
NewNoHistoricalRoundsComm
())
receivedRCB
,
sendResults
,
NewNoHistoricalRoundsComm
())
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Error in happy path: %v"
,
err
)
t
.
Errorf
(
"Error in happy path: %v"
,
err
)
...
@@ -125,8 +113,8 @@ func TestClient_GetRoundResults_FailedRounds(t *testing.T) {
...
@@ -125,8 +113,8 @@ func TestClient_GetRoundResults_FailedRounds(t *testing.T) {
// Sleep to allow the report to come through the pipeline
// Sleep to allow the report to come through the pipeline
time
.
Sleep
(
2
*
time
.
Second
)
time
.
Sleep
(
2
*
time
.
Second
)
// If no rounds have
timed out or no round
failed, this test has failed
// If no rounds have failed, this test has failed
if
!
receivedRCB
.
timedOut
||
receivedRCB
.
allRoundsSucceeded
{
if
receivedRCB
.
allRoundsSucceeded
{
t
.
Errorf
(
"Expected some rounds to fail and others to timeout. "
+
t
.
Errorf
(
"Expected some rounds to fail and others to timeout. "
+
"
\n\t
TimedOut: %v"
+
"
\n\t
TimedOut: %v"
+
"
\n\t
allRoundsSucceeded: %v"
,
receivedRCB
.
timedOut
,
receivedRCB
.
allRoundsSucceeded
)
"
\n\t
allRoundsSucceeded: %v"
,
receivedRCB
.
timedOut
,
receivedRCB
.
allRoundsSucceeded
)
...
@@ -134,40 +122,6 @@ func TestClient_GetRoundResults_FailedRounds(t *testing.T) {
...
@@ -134,40 +122,6 @@ func TestClient_GetRoundResults_FailedRounds(t *testing.T) {
}
}
// Force some timeouts by not populating the entire results channel
func
TestClient_GetRoundResults_Timeout
(
t
*
testing
.
T
)
{
// Populate a round list to request
var
roundList
[]
id
.
Round
for
i
:=
0
;
i
<
numRounds
;
i
++
{
roundList
=
append
(
roundList
,
id
.
Round
(
i
))
}
// Generate a results which never sends (empty chan)
sendResults
:=
make
(
chan
ds
.
EventReturn
)
// Create a new copy of the test client for this test
client
:=
&
Client
{}
*
client
=
*
testClient
// Call the round results
receivedRCB
:=
NewMockRoundCB
()
err
:=
client
.
getRoundResults
(
roundList
,
time
.
Duration
(
10
)
*
time
.
Millisecond
,
receivedRCB
,
sendResults
,
NewNoHistoricalRoundsComm
())
if
err
!=
nil
{
t
.
Errorf
(
"Error in happy path: %v"
,
err
)
}
// Sleep to allow the report to come through the pipeline
time
.
Sleep
(
2
*
time
.
Second
)
// If no rounds have timed out , this test has failed
if
!
receivedRCB
.
timedOut
{
t
.
Errorf
(
"Unexpected round failures in happy path. "
+
"Expected all rounds to succeed with no timeouts."
+
"
\n\t
TimedOut: %v"
,
receivedRCB
.
timedOut
)
}
}
// Use the historical rounds interface which actually sends back rounds
// Use the historical rounds interface which actually sends back rounds
func
TestClient_GetRoundResults_HistoricalRounds
(
t
*
testing
.
T
)
{
func
TestClient_GetRoundResults_HistoricalRounds
(
t
*
testing
.
T
)
{
// Populate a round list to request
// Populate a round list to request
...
@@ -181,7 +135,9 @@ func TestClient_GetRoundResults_HistoricalRounds(t *testing.T) {
...
@@ -181,7 +135,9 @@ func TestClient_GetRoundResults_HistoricalRounds(t *testing.T) {
for
i
:=
0
;
i
<
numRounds
;
i
++
{
for
i
:=
0
;
i
<
numRounds
;
i
++
{
// Skip sending rounds intended for historical rounds comm
// Skip sending rounds intended for historical rounds comm
if
i
==
failedHistoricalRoundID
||
if
i
==
failedHistoricalRoundID
||
i
==
completedHistoricalRoundID
{
continue
}
i
==
completedHistoricalRoundID
{
continue
}
sendResults
<-
ds
.
EventReturn
{
sendResults
<-
ds
.
EventReturn
{
RoundInfo
:
&
pb
.
RoundInfo
{
RoundInfo
:
&
pb
.
RoundInfo
{
...
@@ -192,10 +148,13 @@ func TestClient_GetRoundResults_HistoricalRounds(t *testing.T) {
...
@@ -192,10 +148,13 @@ func TestClient_GetRoundResults_HistoricalRounds(t *testing.T) {
}
}
}
}
// Create a new copy of the test client for this test
// Create a new copy of the test client for this test
client
:=
&
Client
{}
client
,
err
:=
newTestingClient
(
t
)
*
client
=
*
testClient
if
err
!=
nil
{
t
.
Errorf
(
"Failed in setup: %v"
,
err
)
}
// Overpopulate the round buffer, ensuring a circle back of the ring buffer
// Overpopulate the round buffer, ensuring a circle back of the ring buffer
...
@@ -208,19 +167,59 @@ func TestClient_GetRoundResults_HistoricalRounds(t *testing.T) {
...
@@ -208,19 +167,59 @@ func TestClient_GetRoundResults_HistoricalRounds(t *testing.T) {
// Call the round results
// Call the round results
receivedRCB
:=
NewMockRoundCB
()
receivedRCB
:=
NewMockRoundCB
()
err
:
=
client
.
getRoundResults
(
roundList
,
time
.
Duration
(
10
)
*
time
.
Millisecond
,
err
=
client
.
getRoundResults
(
roundList
,
time
.
Duration
(
10
)
*
time
.
Millisecond
,
receivedRCB
,
sendResults
,
NewHistoricalRoundsComm
())
receivedRCB
,
sendResults
,
NewHistoricalRoundsComm
())
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Error in happy path: %v"
,
err
)
t
.
Errorf
(
"Error in happy path: %v"
,
err
)
}
}
// Sleep to allow the report to come through the pipeline
// Sleep to allow the report to come through the pipeline
time
.
Sleep
(
2
*
time
.
Second
)
time
.
Sleep
(
2
*
time
.
Second
)
// If no round failed, this test has failed
// If no round failed, this test has failed
if
receivedRCB
.
allRoundsSucceeded
{
if
receivedRCB
.
allRoundsSucceeded
{
t
.
Errorf
(
"Expected historical rounds to have a failure."
)
}
}
// Force some timeouts by not populating the entire results channel
func
TestClient_GetRoundResults_Timeout
(
t
*
testing
.
T
)
{
// Populate a round list to request
var
roundList
[]
id
.
Round
for
i
:=
0
;
i
<
numRounds
;
i
++
{
roundList
=
append
(
roundList
,
id
.
Round
(
i
))
}
// Create a broken channel which will never send,
// forcing a timeout
var
sendResults
chan
ds
.
EventReturn
sendResults
=
nil
// Create a new copy of the test client for this test
client
,
err
:=
newTestingClient
(
t
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed in setup: %v"
,
err
)
}
// Call the round results
receivedRCB
:=
NewMockRoundCB
()
err
=
client
.
getRoundResults
(
roundList
,
time
.
Duration
(
10
)
*
time
.
Millisecond
,
receivedRCB
,
sendResults
,
NewNoHistoricalRoundsComm
())
if
err
!=
nil
{
t
.
Errorf
(
"Error in happy path: %v"
,
err
)
}
// Sleep to allow the report to come through the pipeline
time
.
Sleep
(
2
*
time
.
Second
)
// If no rounds have timed out , this test has failed
if
!
receivedRCB
.
timedOut
{
t
.
Errorf
(
"Unexpected round failures in happy path. "
+
t
.
Errorf
(
"Unexpected round failures in happy path. "
+
"Expected all rounds to succeed with no timeouts."
+
"Expected all rounds to succeed with no timeouts."
+
"
\n\t
TimedOut: %v"
+
"
\n\t
TimedOut: %v"
,
receivedRCB
.
timedOut
)
"
\n\t
allRoundsSucceeded: %v"
,
receivedRCB
.
timedOut
,
receivedRCB
.
allRoundsSucceeded
)
}
}
}
}
This diff is collapsed.
Click to expand it.
api/utilsInterfaces_test.go
+
0
−
3
View file @
c9e22d7c
...
@@ -7,7 +7,6 @@
...
@@ -7,7 +7,6 @@
package
api
package
api
import
(
import
(
"fmt"
"gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/interfaces/message"
"gitlab.com/elixxir/client/interfaces/message"
"gitlab.com/elixxir/client/interfaces/params"
"gitlab.com/elixxir/client/interfaces/params"
...
@@ -36,8 +35,6 @@ func NewMockRoundCB() *mockRoundCallback {
...
@@ -36,8 +35,6 @@ func NewMockRoundCB() *mockRoundCallback {
// Report simply stores the passed in values in the structure
// Report simply stores the passed in values in the structure
func
(
mrc
*
mockRoundCallback
)
Report
(
allRoundsSucceeded
,
timedOut
bool
,
func
(
mrc
*
mockRoundCallback
)
Report
(
allRoundsSucceeded
,
timedOut
bool
,
rounds
map
[
id
.
Round
]
RoundResult
)
{
rounds
map
[
id
.
Round
]
RoundResult
)
{
fmt
.
Printf
(
"allRoundsSucceeded: %v
\n
"
,
allRoundsSucceeded
)
fmt
.
Printf
(
"timedOut: %v
\n
"
,
timedOut
)
mrc
.
allRoundsSucceeded
=
allRoundsSucceeded
mrc
.
allRoundsSucceeded
=
allRoundsSucceeded
mrc
.
timedOut
=
timedOut
mrc
.
timedOut
=
timedOut
...
...
This diff is collapsed.
Click to expand it.
api/utils_test.go
+
5
−
7
View file @
c9e22d7c
...
@@ -58,7 +58,6 @@ func newTestingClient(face interface{}) (*Client, error) {
...
@@ -58,7 +58,6 @@ func newTestingClient(face interface{}) (*Client, error) {
Manager
:
commsManager
,
Manager
:
commsManager
,
}
}
thisInstance
,
err
:=
network
.
NewInstanceTesting
(
instanceComms
,
def
,
def
,
nil
,
nil
,
face
)
thisInstance
,
err
:=
network
.
NewInstanceTesting
(
instanceComms
,
def
,
def
,
nil
,
nil
,
face
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
return
nil
,
nil
...
@@ -149,5 +148,4 @@ func signRoundInfo(ri *pb.RoundInfo) error {
...
@@ -149,5 +148,4 @@ func signRoundInfo(ri *pb.RoundInfo) error {
return
signature
.
Sign
(
ri
,
ourPrivateKey
)
return
signature
.
Sign
(
ri
,
ourPrivateKey
)
}
}
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