Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
d4a17ae7
Commit
d4a17ae7
authored
6 years ago
by
Michael Schurter
Browse files
Options
Download
Email Patches
Plain Diff
test: port TestTaskRunner_DriverNetwork from 0.8
parent
234f644b
Branches unavailable
v1.4.3
v1.4.2
v1.4.1
v1.4.0
v1.4.0-rc.1
v1.4.0-beta.1
v1.3.8
v1.3.7
v1.3.6
v1.3.5
v1.3.4
v1.3.3
v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc.1
v1.3.0-beta.1
v1.2.15
v1.2.14
v1.2.13
v1.2.12
v1.2.11
v1.2.10
v1.2.9
v1.2.8
v1.2.7
v1.2.6
v1.2.5
v1.2.4
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc1
v1.2.0-beta1
v1.1.18
v1.1.17
v1.1.16
v1.1.15
v1.1.14
v1.1.13
v1.1.12
v1.1.11
v1.1.10
v1.1.9
v1.1.8
v1.1.7
v1.1.6
v1.1.5
v1.1.4
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.1.0-rc1
v1.1.0-beta1
v1.0.18
v1.0.17
v1.0.16
v1.0.15
v1.0.14
v1.0.13
v1.0.12
v1.0.11
v1.0.10
v1.0.9
v1.0.8
v1.0.7
v1.0.6
v1.0.5
v1.0.4
v1.0.3
v1.0.2
v1.0.1
v1.0.0
v1.0.0-rc1
v1.0.0-beta3
v1.0.0-beta2
v0.12.12
v0.12.11
v0.12.10
v0.12.9
v0.12.8
v0.12.7
v0.12.6
v0.12.5
v0.12.4
v0.12.4-rc1
v0.12.3
v0.12.2
v0.12.1
v0.12.0
v0.12.0-rc1
v0.12.0-beta2
v0.12.0-beta1
v0.11.8
v0.11.7
v0.11.6
v0.11.5
v0.11.4
v0.11.3
v0.11.2
v0.11.1
v0.11.0
v0.11.0-rc1
v0.11.0-beta2
v0.11.0-beta1
v0.10.9
v0.10.8
v0.10.7
v0.10.6
v0.10.5
v0.10.4
v0.10.4-rc1
v0.10.3
v0.10.2
v0.10.2-rc1
v0.10.1
v0.10.0
v0.10.0-rc1
v0.10.0-connect1
v0.10.0-beta1
v0.9.7
v0.9.6
v0.9.5
v0.9.4
v0.9.4-rc1
v0.9.3
v0.9.2
v0.9.2-rc1
v0.9.1
v0.9.1-rc1
v0.9.0
v0.9.0-rc2
v0.9.0-rc1
v0.9.0-beta3
nightly
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
client/allocrunner/taskrunner/task_runner_test.go
+133
-0
client/allocrunner/taskrunner/task_runner_test.go
with
133 additions
and
0 deletions
+133
-0
client/allocrunner/taskrunner/task_runner_test.go
+
133
-
0
View file @
d4a17ae7
...
...
@@ -8,6 +8,7 @@ import (
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
"time"
...
...
@@ -997,6 +998,138 @@ func TestTaskRunner_Download_Retries(t *testing.T) {
require
.
Equal
(
t
,
structs
.
TaskNotRestarting
,
state
.
Events
[
7
]
.
Type
)
}
// TestTaskRunner_DriverNetwork asserts that a driver's network is properly
// used in services and checks.
func
TestTaskRunner_DriverNetwork
(
t
*
testing
.
T
)
{
t
.
Parallel
()
alloc
:=
mock
.
Alloc
()
task
:=
alloc
.
Job
.
TaskGroups
[
0
]
.
Tasks
[
0
]
task
.
Driver
=
"mock_driver"
task
.
Config
=
map
[
string
]
interface
{}{
"run_for"
:
"100s"
,
"driver_ip"
:
"10.1.2.3"
,
"driver_port_map"
:
"http:80"
,
}
// Create services and checks with custom address modes to exercise
// address detection logic
task
.
Services
=
[]
*
structs
.
Service
{
{
Name
:
"host-service"
,
PortLabel
:
"http"
,
AddressMode
:
"host"
,
Checks
:
[]
*
structs
.
ServiceCheck
{
{
Name
:
"driver-check"
,
Type
:
"tcp"
,
PortLabel
:
"1234"
,
AddressMode
:
"driver"
,
},
},
},
{
Name
:
"driver-service"
,
PortLabel
:
"5678"
,
AddressMode
:
"driver"
,
Checks
:
[]
*
structs
.
ServiceCheck
{
{
Name
:
"host-check"
,
Type
:
"tcp"
,
PortLabel
:
"http"
,
},
{
Name
:
"driver-label-check"
,
Type
:
"tcp"
,
PortLabel
:
"http"
,
AddressMode
:
"driver"
,
},
},
},
}
conf
,
cleanup
:=
testTaskRunnerConfig
(
t
,
alloc
,
task
.
Name
)
defer
cleanup
()
// Use a mock agent to test for services
consulAgent
:=
agentconsul
.
NewMockAgent
()
consulClient
:=
agentconsul
.
NewServiceClient
(
consulAgent
,
conf
.
Logger
,
true
)
defer
consulClient
.
Shutdown
()
go
consulClient
.
Run
()
conf
.
Consul
=
consulClient
tr
,
err
:=
NewTaskRunner
(
conf
)
require
.
NoError
(
t
,
err
)
defer
tr
.
Kill
(
context
.
Background
(),
structs
.
NewTaskEvent
(
"cleanup"
))
go
tr
.
Run
()
// Wait for the task to start
testWaitForTaskToStart
(
t
,
tr
)
testutil
.
WaitForResult
(
func
()
(
bool
,
error
)
{
services
,
_
:=
consulAgent
.
Services
()
if
n
:=
len
(
services
);
n
!=
2
{
return
false
,
fmt
.
Errorf
(
"expected 2 services, but found %d"
,
n
)
}
for
_
,
s
:=
range
services
{
switch
s
.
Service
{
case
"host-service"
:
if
expected
:=
"192.168.0.100"
;
s
.
Address
!=
expected
{
return
false
,
fmt
.
Errorf
(
"expected host-service to have IP=%s but found %s"
,
expected
,
s
.
Address
)
}
case
"driver-service"
:
if
expected
:=
"10.1.2.3"
;
s
.
Address
!=
expected
{
return
false
,
fmt
.
Errorf
(
"expected driver-service to have IP=%s but found %s"
,
expected
,
s
.
Address
)
}
if
expected
:=
5678
;
s
.
Port
!=
expected
{
return
false
,
fmt
.
Errorf
(
"expected driver-service to have port=%d but found %d"
,
expected
,
s
.
Port
)
}
default
:
return
false
,
fmt
.
Errorf
(
"unexpected service: %q"
,
s
.
Service
)
}
}
checks
:=
consulAgent
.
CheckRegs
()
if
n
:=
len
(
checks
);
n
!=
3
{
return
false
,
fmt
.
Errorf
(
"expected 3 checks, but found %d"
,
n
)
}
for
_
,
check
:=
range
checks
{
switch
check
.
Name
{
case
"driver-check"
:
if
expected
:=
"10.1.2.3:1234"
;
check
.
TCP
!=
expected
{
return
false
,
fmt
.
Errorf
(
"expected driver-check to have address %q but found %q"
,
expected
,
check
.
TCP
)
}
case
"driver-label-check"
:
if
expected
:=
"10.1.2.3:80"
;
check
.
TCP
!=
expected
{
return
false
,
fmt
.
Errorf
(
"expected driver-label-check to have address %q but found %q"
,
expected
,
check
.
TCP
)
}
case
"host-check"
:
if
expected
:=
"192.168.0.100:"
;
!
strings
.
HasPrefix
(
check
.
TCP
,
expected
)
{
return
false
,
fmt
.
Errorf
(
"expected host-check to have address start with %q but found %q"
,
expected
,
check
.
TCP
)
}
default
:
return
false
,
fmt
.
Errorf
(
"unexpected check: %q"
,
check
.
Name
)
}
}
return
true
,
nil
},
func
(
err
error
)
{
services
,
_
:=
consulAgent
.
Services
()
for
_
,
s
:=
range
services
{
t
.
Logf
(
pretty
.
Sprint
(
"Service: "
,
s
))
}
for
_
,
c
:=
range
consulAgent
.
CheckRegs
()
{
t
.
Logf
(
pretty
.
Sprint
(
"Check: "
,
c
))
}
require
.
NoError
(
t
,
err
)
})
}
// testWaitForTaskToStart waits for the task to be running or fails the test
func
testWaitForTaskToStart
(
t
*
testing
.
T
,
tr
*
TaskRunner
)
{
testutil
.
WaitForResult
(
func
()
(
bool
,
error
)
{
...
...
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
Menu
Projects
Groups
Snippets
Help