Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
c2ab4c9c
Commit
c2ab4c9c
authored
5 years ago
by
Jasmine Dahilig
Committed by
Mahmood Ali
5 years ago
Browse files
Options
Download
Email Patches
Plain Diff
add test for lifecycle coordinator
parent
ae2a4bc7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
client/allocrunner/task_hook_coordinator_test.go
+31
-0
client/allocrunner/task_hook_coordinator_test.go
nomad/mock/mock.go
+18
-0
nomad/mock/mock.go
with
49 additions
and
0 deletions
+49
-0
client/allocrunner/task_hook_coordinator_test.go
+
31
-
0
View file @
c2ab4c9c
...
@@ -24,3 +24,34 @@ func TestTaskHookCoordinator_OnlyMainApp(t *testing.T) {
...
@@ -24,3 +24,34 @@ func TestTaskHookCoordinator_OnlyMainApp(t *testing.T) {
require
.
Fail
(
t
,
"channel wasn't closed"
)
require
.
Fail
(
t
,
"channel wasn't closed"
)
}
}
}
}
func
TestTaskHookCoordinator_Prestart
(
t
*
testing
.
T
)
{
alloc
:=
mock
.
Alloc
()
tasks
:=
alloc
.
Job
.
TaskGroups
[
0
]
.
Tasks
logger
:=
testlog
.
HCLogger
(
t
)
tasks
=
append
(
tasks
,
mock
.
InitTask
())
tasks
=
append
(
tasks
,
mock
.
SidecarTask
())
coord
:=
newTaskHookCoordinator
(
logger
,
tasks
)
mainCh
:=
coord
.
startConditionForTask
(
tasks
[
0
])
initCh
:=
coord
.
startConditionForTask
(
tasks
[
1
])
sideCh
:=
coord
.
startConditionForTask
(
tasks
[
2
])
select
{
case
_
,
ok
:=
<-
initCh
:
require
.
False
(
t
,
ok
)
case
_
,
ok
:=
<-
sideCh
:
require
.
False
(
t
,
ok
)
default
:
require
.
Fail
(
t
,
"prestart channels weren't closed"
)
}
select
{
case
<-
mainCh
:
require
.
Fail
(
t
,
"channel was closed, should be open"
)
default
:
// channel for main task is open, which is correct: coordinator should
// block all other tasks until prestart tasks are completed
}
}
This diff is collapsed.
Click to expand it.
nomad/mock/mock.go
+
18
-
0
View file @
c2ab4c9c
...
@@ -1013,3 +1013,21 @@ func ACLManagementToken() *structs.ACLToken {
...
@@ -1013,3 +1013,21 @@ func ACLManagementToken() *structs.ACLToken {
ModifyIndex
:
20
,
ModifyIndex
:
20
,
}
}
}
}
func
SidecarTask
()
*
structs
.
Task
{
return
&
structs
.
Task
{
Lifecycle
:
&
structs
.
TaskLifecycleConfig
{
Hook
:
structs
.
TaskLifecycleHookPrestart
,
BlockUntil
:
structs
.
TaskLifecycleBlockUntilRunning
,
},
}
}
func
InitTask
()
*
structs
.
Task
{
return
&
structs
.
Task
{
Lifecycle
:
&
structs
.
TaskLifecycleConfig
{
Hook
:
structs
.
TaskLifecycleHookPrestart
,
BlockUntil
:
structs
.
TaskLifecycleBlockUntilCompleted
,
},
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment