Skip to content
GitLab
Next
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
buildgrid
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
Show more breadcrumbs
BuildGrid
buildgrid
Commits
66119b01
Commit
66119b01
authored
6 years ago
by
Martin Blanchard
Browse files
Options
Downloads
Patches
Plain Diff
tests/utils/server.py: New server helper
#135
parent
1a8dff34
No related branches found
No related tags found
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/utils/server.py
+78
-0
78 additions, 0 deletions
tests/utils/server.py
with
78 additions
and
0 deletions
tests/utils/server.py
0 → 100644
+
78
−
0
View file @
66119b01
# Copyright (C) 2018 Bloomberg LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# <http://www.apache.org/licenses/LICENSE-2.0>
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
contextlib
import
contextmanager
import
multiprocessing
import
signal
import
pytest_cov
from
buildgrid._app.settings
import
parser
from
buildgrid.server.instance
import
BuildGridServer
@contextmanager
def
serve
(
configuration
):
server
=
Server
(
configuration
)
try
:
yield
server
finally
:
server
.
quit
()
class
Server
:
def
__init__
(
self
,
configuration
):
self
.
configuration
=
configuration
self
.
__queue
=
multiprocessing
.
Queue
()
self
.
__process
=
multiprocessing
.
Process
(
target
=
Server
.
serve
,
args
=
(
self
.
__queue
,
self
.
configuration
))
self
.
__process
.
start
()
self
.
port
=
self
.
__queue
.
get
()
self
.
remote
=
'
localhost:{}
'
.
format
(
self
.
port
)
@classmethod
def
serve
(
cls
,
queue
,
configuration
):
pytest_cov
.
embed
.
cleanup_on_sigterm
()
server
=
BuildGridServer
()
def
__signal_handler
(
signum
,
frame
):
server
.
stop
()
signal
.
signal
(
signal
.
SIGINT
,
signal
.
SIG_IGN
)
signal
.
signal
(
signal
.
SIGTERM
,
__signal_handler
)
instances
=
parser
.
get_parser
().
safe_load
(
configuration
)[
'
instances
'
]
for
instance
in
instances
:
instance_name
=
instance
[
'
name
'
]
services
=
instance
[
'
services
'
]
for
service
in
services
:
service
.
register_instance_with_server
(
instance_name
,
server
)
port
=
server
.
add_port
(
'
localhost:0
'
,
None
)
queue
.
put
(
port
)
server
.
start
()
def
quit
(
self
):
if
self
.
__process
:
self
.
__process
.
terminate
()
self
.
__process
.
join
()
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