Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
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
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
0be8b3cd
Commit
0be8b3cd
authored
Jan 29, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check cache in Ci::Runner#online?
parent
b1c40590
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
13 deletions
+50
-13
app/models/ci/runner.rb
app/models/ci/runner.rb
+8
-1
spec/models/ci/runner_spec.rb
spec/models/ci/runner_spec.rb
+42
-12
No files found.
app/models/ci/runner.rb
View file @
0be8b3cd
...
...
@@ -88,7 +88,10 @@ module Ci
end
def
online?
contacted_at
&&
contacted_at
>
self
.
class
.
contact_time_deadline
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
last_seen
=
redis
.
get
(
"
#{
self
.
runner_info_key
}
:contacted_at"
)
||
contacted_at
last_seen
&&
last_seen
>
self
.
class
.
contact_time_deadline
end
end
def
status
...
...
@@ -152,6 +155,10 @@ module Ci
ensure_runner_queue_value
==
value
if
value
.
present?
end
def
runner_info_key
"runner:info:
#{
self
.
id
}
"
end
private
def
cleanup_runner_queue
...
...
spec/models/ci/runner_spec.rb
View file @
0be8b3cd
...
...
@@ -95,28 +95,58 @@ describe Ci::Runner do
subject
{
runner
.
online?
}
context
'n
ever contacted
'
do
context
'n
o cache value
'
do
before
do
runner
.
contacted_at
=
nil
stub_redis
(
"
#{
runner
.
runner_info_key
}
:contacted_at"
,
nil
)
end
it
{
is_expected
.
to
be_falsey
}
end
context
'never contacted'
do
before
do
runner
.
contacted_at
=
nil
end
context
'contacted long time ago time'
do
before
do
runner
.
contacted_at
=
1
.
year
.
ago
it
{
is_expected
.
to
be_falsey
}
end
context
'contacted long time ago time'
do
before
do
runner
.
contacted_at
=
1
.
year
.
ago
end
it
{
is_expected
.
to
be_falsey
}
end
it
{
is_expected
.
to
be_falsey
}
context
'contacted 1s ago'
do
before
do
runner
.
contacted_at
=
1
.
second
.
ago
end
it
{
is_expected
.
to
be_truthy
}
end
end
context
'contacted 1s ago'
do
before
do
runner
.
contacted_at
=
1
.
second
.
ago
context
'with cache value'
do
context
'contacted long time ago time'
do
before
do
stub_redis
(
"
#{
runner
.
runner_info_key
}
:contacted_at"
,
1
.
year
.
ago
.
to_s
)
end
it
{
is_expected
.
to
be_falsey
}
end
context
'contacted 1s ago'
do
before
do
stub_redis
(
"
#{
runner
.
runner_info_key
}
:contacted_at"
,
1
.
second
.
ago
.
to_s
)
end
it
{
is_expected
.
to
be_truthy
}
end
end
it
{
is_expected
.
to
be_truthy
}
def
stub_redis
(
key
,
value
)
redis
=
double
allow
(
Gitlab
::
Redis
::
SharedState
).
to
receive
(
:with
).
and_yield
(
redis
)
allow
(
redis
).
to
receive
(
:get
).
with
(
key
).
and_return
(
value
)
end
end
...
...
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