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
61034e85
Commit
61034e85
authored
Nov 19, 2021
by
Roy Zwambag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow daemon to receive a synchronous option that joins threads
parent
cc2f3a8c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
5 deletions
+34
-5
lib/gitlab/daemon.rb
lib/gitlab/daemon.rb
+10
-5
spec/lib/gitlab/daemon_spec.rb
spec/lib/gitlab/daemon_spec.rb
+24
-0
No files found.
lib/gitlab/daemon.rb
View file @
61034e85
...
...
@@ -2,16 +2,16 @@
module
Gitlab
class
Daemon
def
self
.
initialize_instance
(
*
args
)
def
self
.
initialize_instance
(
...
)
raise
"
#{
name
}
singleton instance already initialized"
if
@instance
@instance
=
new
(
*
args
)
@instance
=
new
(
...
)
Kernel
.
at_exit
(
&
@instance
.
method
(
:stop
))
@instance
end
def
self
.
instance
(
*
args
)
@instance
||=
initialize_instance
(
*
args
)
def
self
.
instance
(
...
)
@instance
||=
initialize_instance
(
...
)
end
attr_reader
:thread
...
...
@@ -20,7 +20,8 @@ module Gitlab
!
thread
.
nil?
end
def
initialize
def
initialize
(
**
options
)
@synchronous
=
options
[
:synchronous
]
@mutex
=
Mutex
.
new
end
...
...
@@ -43,6 +44,10 @@ module Gitlab
Thread
.
current
.
name
=
thread_name
run_thread
end
@thread
.
join
if
@synchronous
@thread
end
end
end
...
...
spec/lib/gitlab/daemon_spec.rb
View file @
61034e85
...
...
@@ -46,6 +46,30 @@ RSpec.describe Gitlab::Daemon do
expect
(
subject
).
to
have_received
(
:run_thread
)
end
context
'@synchronous'
do
context
'when @synchronous is set to true'
do
subject
{
described_class
.
instance
(
synchronous:
true
)
}
it
'calls join on the thread'
do
# Thread has to be run in a block, expect_next_instance_of does not support this.
expect_any_instance_of
(
Thread
).
to
receive
(
:join
)
# rubocop:disable RSpec/AnyInstanceOf
subject
.
start
end
end
context
'when @synchronous is not set to a truthy value'
do
subject
{
described_class
.
instance
}
it
'does not call join on the thread'
do
# Thread has to be run in a block, expect_next_instance_of does not support this.
expect_any_instance_of
(
Thread
).
not_to
receive
(
:join
)
# rubocop:disable RSpec/AnyInstanceOf
subject
.
start
end
end
end
end
describe
'#stop'
do
...
...
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