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
e6266d2e
Commit
e6266d2e
authored
Aug 30, 2022
by
Benjamin Wenger
Browse files
Options
Downloads
Patches
Plain Diff
added tests for manager.go
parent
66ae7eb4
No related branches found
No related tags found
5 merge requests
!510
Release
,
!419
rewrote the health tracker to both consider if there are waiting rounds and...
,
!371
[Channel RSAtoPrivate] Implement Reverse Asymmetric in Client/Broadcast
,
!354
Channels impl
,
!340
Project/channels
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
channels/joinedChannel_test.go
+10
-3
10 additions, 3 deletions
channels/joinedChannel_test.go
channels/manager_test.go
+72
-0
72 additions, 0 deletions
channels/manager_test.go
with
82 additions
and
3 deletions
channels/joinedChannel_test.go
+
10
−
3
View file @
e6266d2e
...
@@ -495,10 +495,17 @@ func (m *mockBroadcastClient) RemoveIdentity(*id.ID)
...
@@ -495,10 +495,17 @@ func (m *mockBroadcastClient) RemoveIdentity(*id.ID)
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// mockEventModel adheres to the EventModel interface.
// mockEventModel adheres to the EventModel interface.
type
mockEventModel
struct
{}
type
mockEventModel
struct
{
joinedCh
*
cryptoBroadcast
.
Channel
leftCh
*
id
.
ID
}
func
(
m
*
mockEventModel
)
JoinChannel
(
*
cryptoBroadcast
.
Channel
)
{}
func
(
m
*
mockEventModel
)
JoinChannel
(
c
*
cryptoBroadcast
.
Channel
)
{
func
(
m
*
mockEventModel
)
LeaveChannel
(
*
id
.
ID
)
{}
m
.
joinedCh
=
c
}
func
(
m
*
mockEventModel
)
LeaveChannel
(
c
*
id
.
ID
)
{
m
.
leftCh
=
c
}
func
(
m
*
mockEventModel
)
ReceiveMessage
(
*
id
.
ID
,
cryptoChannel
.
MessageID
,
string
,
func
(
m
*
mockEventModel
)
ReceiveMessage
(
*
id
.
ID
,
cryptoChannel
.
MessageID
,
string
,
string
,
time
.
Time
,
time
.
Duration
,
rounds
.
Round
)
{
string
,
time
.
Time
,
time
.
Duration
,
rounds
.
Round
)
{
}
}
...
...
This diff is collapsed.
Click to expand it.
channels/manager_test.go
+
72
−
0
View file @
e6266d2e
package
channels
package
channels
import
(
import
(
"gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/elixxir/crypto/fastRNG"
"gitlab.com/elixxir/ekv"
"gitlab.com/xx_network/crypto/csprng"
"os"
"os"
"testing"
"testing"
"time"
jww
"github.com/spf13/jwalterweatherman"
jww
"github.com/spf13/jwalterweatherman"
)
)
...
@@ -13,3 +18,70 @@ func TestMain(m *testing.M) {
...
@@ -13,3 +18,70 @@ func TestMain(m *testing.M) {
jww
.
SetStdoutThreshold
(
jww
.
LevelWarn
)
jww
.
SetStdoutThreshold
(
jww
.
LevelWarn
)
os
.
Exit
(
m
.
Run
())
os
.
Exit
(
m
.
Run
())
}
}
func
TestManager_JoinChannel
(
t
*
testing
.
T
)
{
mem
:=
&
mockEventModel
{}
m
:=
NewManager
(
versioned
.
NewKV
(
ekv
.
MakeMemstore
()),
new
(
mockBroadcastClient
),
fastRNG
.
NewStreamGenerator
(
1
,
1
,
csprng
.
NewSystemRNG
),
new
(
mockNameService
),
mem
)
.
(
*
manager
)
ch
,
_
,
err
:=
newTestChannel
(
"name"
,
"description"
,
m
.
rng
.
GetStream
())
if
err
!=
nil
{
t
.
Errorf
(
"Failed to create new channel: %+v"
,
err
)
}
err
=
m
.
JoinChannel
(
ch
)
if
err
!=
nil
{
t
.
Fatalf
(
"Join Channel Errored: %s"
,
err
)
}
if
_
,
exists
:=
m
.
channels
[
*
ch
.
ReceptionID
];
!
exists
{
t
.
Errorf
(
"Channel %s not added to channel map."
,
ch
.
Name
)
}
//wait because the event model is called in another thread
time
.
Sleep
(
1
*
time
.
Second
)
if
mem
.
joinedCh
==
nil
{
t
.
Errorf
(
"the channel join call was not propogated to the event "
+
"model"
)
}
}
func
TestManager_LeaveChannel
(
t
*
testing
.
T
)
{
mem
:=
&
mockEventModel
{}
m
:=
NewManager
(
versioned
.
NewKV
(
ekv
.
MakeMemstore
()),
new
(
mockBroadcastClient
),
fastRNG
.
NewStreamGenerator
(
1
,
1
,
csprng
.
NewSystemRNG
),
new
(
mockNameService
),
mem
)
.
(
*
manager
)
ch
,
_
,
err
:=
newTestChannel
(
"name"
,
"description"
,
m
.
rng
.
GetStream
())
if
err
!=
nil
{
t
.
Errorf
(
"Failed to create new channel: %+v"
,
err
)
}
err
=
m
.
JoinChannel
(
ch
)
if
err
!=
nil
{
t
.
Fatalf
(
"Join Channel Errored: %s"
,
err
)
}
err
=
m
.
LeaveChannel
(
ch
.
ReceptionID
)
if
err
!=
nil
{
t
.
Fatalf
(
"Leave Channel Errored: %s"
,
err
)
}
if
_
,
exists
:=
m
.
channels
[
*
ch
.
ReceptionID
];
exists
{
t
.
Errorf
(
"Channel %s still in map."
,
ch
.
Name
)
}
//wait because the event model is called in another thread
time
.
Sleep
(
1
*
time
.
Second
)
if
mem
.
leftCh
==
nil
{
t
.
Errorf
(
"the channel join call was not propogated to the event "
+
"model"
)
}
}
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