Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
autoradio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
ale
autoradio
Commits
51d682cd
Commit
51d682cd
authored
10 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
more tests for node.go
parent
03a67c17
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
node/node.go
+3
-5
3 additions, 5 deletions
node/node.go
node/node_test.go
+33
-11
33 additions, 11 deletions
node/node_test.go
util/mock_etcd.go
+1
-0
1 addition, 0 deletions
util/mock_etcd.go
with
37 additions
and
16 deletions
node/node.go
+
3
−
5
View file @
51d682cd
...
...
@@ -216,11 +216,10 @@ func (w *configWatcher) Start() {
// An active streaming node, managing the local icecast server.
type
RadioNode
struct
{
c
onfig
*
clusterConfig
c
lient
autoradio
.
EtcdClient
config
*
clusterConfig
name
string
ips
[]
net
.
IP
client
autoradio
.
EtcdClient
me
*
masterelection
.
MasterElection
watcher
*
configWatcher
icecast
Controller
...
...
@@ -234,8 +233,7 @@ func NewRadioNode(name string, ips []net.IP, netDev string, bwLimit float64, cli
config
:=
newClusterConfig
()
// Network updates trigger icecast reconfiguration. This
// channel is used as an 'event', no more than one entry will
// be queued.
// channel is used as an event signal.
upch
:=
make
(
chan
bool
,
1
)
// MasterElection changes trigger an update.
...
...
This diff is collapsed.
Click to expand it.
node/node_test.go
+
33
−
11
View file @
51d682cd
...
...
@@ -49,26 +49,26 @@ func startTestNodes(n int, etcd autoradio.EtcdClient) []*RadioNode {
}
func
loadTestData
(
etcd
autoradio
.
EtcdClient
)
{
etcd
.
Set
(
autoradio
.
MountPrefix
+
"
/
test.ogg"
,
etcd
.
Set
(
autoradio
.
MountPrefix
+
"test.ogg"
,
`{"Name": "/test.ogg", "Username": "source1", "Password": "foo"}`
,
86400
)
}
func
countMasters
(
nodes
[]
*
RadioNode
)
int
{
var
masters
int
for
_
,
n
:=
range
nodes
{
if
n
.
me
.
IsMaster
()
{
masters
++
}
}
return
masters
}
func
TestRadioNode_MasterElection
(
t
*
testing
.
T
)
{
etcd
:=
util
.
NewTestEtcdClient
()
loadTestData
(
etcd
)
nodes
:=
startTestNodes
(
3
,
etcd
)
countMasters
:=
func
(
nodes
[]
*
RadioNode
)
int
{
var
masters
int
for
_
,
n
:=
range
nodes
{
if
n
.
me
.
IsMaster
()
{
masters
++
}
}
return
masters
}
// Shut down the nodes one by one, and verify that there is a
// single master among the remaining ones.
for
i
:=
0
;
i
<
3
;
i
++
{
...
...
@@ -79,3 +79,25 @@ func TestRadioNode_MasterElection(t *testing.T) {
time
.
Sleep
(
10
*
time
.
Millisecond
)
}
}
func
TestRadioNode_ConfigChangePropagation
(
t
*
testing
.
T
)
{
etcd
:=
util
.
NewTestEtcdClient
()
loadTestData
(
etcd
)
nodes
:=
startTestNodes
(
3
,
etcd
)
// Wait a bit and modify the stream. Check that the change
// propagates correctly.
time
.
Sleep
(
100
*
time
.
Millisecond
)
etcd
.
Set
(
autoradio
.
MountPrefix
+
"test.ogg"
,
`{"Name": "/test.ogg", "Username": "source2", "Password": "bar"}`
,
86400
)
time
.
Sleep
(
100
*
time
.
Millisecond
)
for
i
:=
0
;
i
<
3
;
i
++
{
username
:=
nodes
[
i
]
.
config
.
GetMount
(
"/test.ogg"
)
.
Username
if
username
!=
"source2"
{
t
.
Errorf
(
"change did not propagate to node %d"
,
i
+
1
)
}
nodes
[
i
]
.
Stop
()
}
}
This diff is collapsed.
Click to expand it.
util/mock_etcd.go
+
1
−
0
View file @
51d682cd
...
...
@@ -120,6 +120,7 @@ func (s *testEtcdServer) Get(key string, recursive, boh bool) (*etcd.Response, e
EtcdIndex
:
s
.
index
,
}
var
nodes
[]
*
etcd
.
Node
key
=
strings
.
TrimSuffix
(
key
,
"/"
)
keyDirPfx
:=
key
+
"/"
for
path
,
datum
:=
range
s
.
data
{
if
path
==
key
||
strings
.
HasPrefix
(
path
,
keyDirPfx
)
{
...
...
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