Skip to content
GitLab
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
230aa7a8
Commit
230aa7a8
authored
6 years ago
by
finn
Browse files
Options
Downloads
Patches
Plain Diff
Adding bot_interface unittests
parent
7acd1516
No related branches found
No related tags found
Loading
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitlab-ci.yml
+1
-1
1 addition, 1 deletion
.gitlab-ci.yml
app/commands/cmd_bot.py
+7
-3
7 additions, 3 deletions
app/commands/cmd_bot.py
buildgrid/bot/bot.py
+16
-19
16 additions, 19 deletions
buildgrid/bot/bot.py
tests/integration/bot_interface.py
+54
-0
54 additions, 0 deletions
tests/integration/bot_interface.py
with
78 additions
and
23 deletions
.gitlab-ci.yml
+
1
−
1
View file @
230aa7a8
...
...
@@ -30,7 +30,7 @@ before_script:
script
:
-
${BGD} server start &
-
sleep
1
# Allow server to boot
-
${BGD} bot --host=0.0.0.0 dummy &
-
${BGD} bot --host=0.0.0.0
--continuous
dummy &
-
${BGD} execute --host=0.0.0.0 request --wait-for-completion
tests-debian-stretch
:
...
...
This diff is collapsed.
Click to expand it.
app/commands/cmd_bot.py
+
7
−
3
View file @
230aa7a8
...
...
@@ -43,15 +43,17 @@ from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_p
from
google.protobuf
import
any_pb2
@click.group
(
short_help
=
'
Create a bot client
'
)
@click.option
(
'
--continuous
'
,
is_flag
=
True
)
@click.option
(
'
--parent
'
,
default
=
'
bgd_test
'
)
@click.option
(
'
--number-of-leases
'
,
default
=
1
)
@click.option
(
'
--port
'
,
default
=
'
50051
'
)
@click.option
(
'
--host
'
,
default
=
'
localhost
'
)
@pass_context
def
cli
(
context
,
host
,
port
,
number_of_leases
,
parent
):
def
cli
(
context
,
host
,
port
,
number_of_leases
,
parent
,
continuous
):
context
.
logger
=
logging
.
getLogger
(
__name__
)
context
.
logger
.
info
(
"
Starting on port {}
"
.
format
(
port
))
context
.
continuous
=
continuous
context
.
channel
=
grpc
.
insecure_channel
(
'
{}:{}
'
.
format
(
host
,
port
))
context
.
number_of_leases
=
number_of_leases
context
.
parent
=
parent
...
...
@@ -71,7 +73,8 @@ def dummy(context):
context
=
context
,
channel
=
context
.
channel
,
parent
=
context
.
parent
,
number_of_leases
=
context
.
number_of_leases
)
number_of_leases
=
context
.
number_of_leases
,
continuous
=
context
.
continuous
)
except
KeyboardInterrupt
:
pass
...
...
@@ -105,7 +108,8 @@ def _work_buildbox(context, remote, port, server_cert, client_key, client_cert,
context
=
context
,
channel
=
context
.
channel
,
parent
=
context
.
parent
,
number_of_leases
=
context
.
number_of_leases
)
number_of_leases
=
context
.
number_of_leases
,
continuous
=
context
.
continuous
)
except
KeyboardInterrupt
:
pass
...
...
This diff is collapsed.
Click to expand it.
buildgrid/bot/bot.py
+
16
−
19
View file @
230aa7a8
...
...
@@ -39,33 +39,31 @@ class Bot(object):
Creates a local BotSession.
"""
def
__init__
(
self
,
work
,
context
,
channel
,
parent
,
number_of_leases
):
def
__init__
(
self
,
work
,
context
,
channel
,
parent
,
number_of_leases
,
continuous
=
True
):
if
not
inspect
.
iscoroutinefunction
(
work
):
raise
BotError
(
"
work function must be async
"
)
print
(
type
(
context
))
self
.
interface
=
bot_interface
.
BotInterface
(
channel
)
self
.
logger
=
logging
.
getLogger
(
__name__
)
self
.
_create_session
(
parent
,
number_of_leases
)
self
.
_work_queue
=
queue
.
Queue
(
maxsize
=
number_of_leases
)
try
:
while
True
:
## TODO: Leases independently finish
## Allow leases to queue finished work independently instead
## of waiting for all to finish
futures
=
[
self
.
_do_work
(
work
,
context
,
lease
)
for
lease
in
self
.
_get_work
()]
if
futures
:
loop
=
asyncio
.
new_event_loop
()
leases_complete
,
_
=
loop
.
run_until_complete
(
asyncio
.
wait
(
futures
))
work_complete
=
[(
lease
.
result
().
id
,
lease
.
result
(),)
for
lease
in
leases_complete
]
self
.
_work_complete
(
work_complete
)
loop
.
close
()
self
.
_update_bot_session
()
time
.
sleep
(
2
)
except
Exception
as
e
:
self
.
logger
.
error
(
e
)
raise
BotError
(
e
)
while
continuous
:
## TODO: Leases independently finish
## Allow leases to queue finished work independently instead
## of waiting for all to finish
futures
=
[
self
.
_do_work
(
work
,
context
,
lease
)
for
lease
in
self
.
_get_work
()]
if
futures
:
loop
=
asyncio
.
new_event_loop
()
leases_complete
,
_
=
loop
.
run_until_complete
(
asyncio
.
wait
(
futures
))
work_complete
=
[(
lease
.
result
().
id
,
lease
.
result
(),)
for
lease
in
leases_complete
]
self
.
_work_complete
(
work_complete
)
loop
.
close
()
self
.
_update_bot_session
()
time
.
sleep
(
2
)
@property
def
bot_session
(
self
):
...
...
@@ -97,7 +95,6 @@ class Bot(object):
def
_get_work
(
self
):
while
not
self
.
_work_queue
.
empty
():
yield
self
.
_work_queue
.
get
()
self
.
_work_queue
.
task_done
()
def
_work_complete
(
self
,
leases_complete
):
"""
Bot updates itself with any completed work.
...
...
This diff is collapsed.
Click to expand it.
tests/integration/bot_interface.py
0 → 100644
+
54
−
0
View file @
230aa7a8
# Copyright (C) 2018 Codethink Limited
#
# 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.
#
# Authors:
# Finn Ball <finn.ball@codethink.co.uk>
import
copy
import
grpc
import
logging
import
mock
import
pytest
import
uuid
from
buildgrid.bot
import
bot
,
bot_interface
async
def
_work_dummy
(
context
,
lease
):
return
lease
class
ContextMock
():
def
__init__
(
self
):
self
.
logger
=
logging
.
getLogger
(
__name__
)
# GRPC context
@pytest.fixture
def
context
():
yield
ContextMock
()
# GRPC context
@pytest.fixture
def
channel
():
yield
mock
.
MagicMock
(
spec
=
grpc
.
insecure_channel
(
''
))
@pytest.fixture
def
instance
(
channel
):
yield
bot
.
Bot
(
work
=
_work_dummy
,
context
=
ContextMock
(),
channel
=
channel
,
parent
=
'
rach
'
,
number_of_leases
=
1
,
continuous
=
False
)
def
test_create_job
(
instance
):
instance
.
bot_session
()
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