Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
250cb010
Commit
250cb010
authored
Jun 11, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/plugin: Only allow client start once, lock
parent
fb2ffde2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
8 deletions
+26
-8
packer/plugin/client.go
packer/plugin/client.go
+10
-8
packer/plugin/client_test.go
packer/plugin/client_test.go
+16
-0
No files found.
packer/plugin/client.go
View file @
250cb010
...
...
@@ -20,6 +20,8 @@ var managedClients = make([]*client, 0, 5)
type
client
struct
{
config
*
ClientConfig
exited
bool
started
bool
startL
sync
.
Mutex
doneLogging
bool
}
...
...
@@ -86,12 +88,7 @@ func NewClient(config *ClientConfig) (c *client) {
config
.
StartTimeout
=
1
*
time
.
Minute
}
c
=
&
client
{
config
,
false
,
false
,
}
c
=
&
client
{
config
:
config
}
if
config
.
Managed
{
managedClients
=
append
(
managedClients
,
c
)
}
...
...
@@ -139,8 +136,13 @@ func (c *client) Kill() {
// Once a client has been started once, it cannot be started again, even if
// it was killed.
func
(
c
*
client
)
Start
()
(
address
string
,
err
error
)
{
// TODO: Make only run once
// TODO: Mutex
c
.
startL
.
Lock
()
defer
c
.
startL
.
Unlock
()
if
c
.
started
{
panic
(
"plugin client already started once"
)
}
c
.
started
=
true
env
:=
[]
string
{
fmt
.
Sprintf
(
"PACKER_PLUGIN_MIN_PORT=%d"
,
c
.
config
.
MinPort
),
...
...
packer/plugin/client_test.go
View file @
250cb010
...
...
@@ -33,6 +33,22 @@ func TestClient(t *testing.T) {
}
}
func
TestClient_Start_Once
(
t
*
testing
.
T
)
{
process
:=
helperProcess
(
"mock"
)
c
:=
NewClient
(
&
ClientConfig
{
Cmd
:
process
})
defer
c
.
Kill
()
defer
func
()
{
p
:=
recover
()
if
p
==
nil
{
t
.
Fatal
(
"should've paniced"
)
}
}()
c
.
Start
()
c
.
Start
()
}
func
TestClient_Start_Timeout
(
t
*
testing
.
T
)
{
config
:=
&
ClientConfig
{
Cmd
:
helperProcess
(
"start-timeout"
),
...
...
Write
Preview
Markdown
is supported
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