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
2ea64369
Commit
2ea64369
authored
Mar 11, 2021
by
jejacks0n
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restore publishing behavior for Gon
parent
d1b11f67
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
34 deletions
+13
-34
app/experiments/application_experiment.rb
app/experiments/application_experiment.rb
+6
-8
spec/experiments/application_experiment_spec.rb
spec/experiments/application_experiment_spec.rb
+7
-26
No files found.
app/experiments/application_experiment.rb
View file @
2ea64369
...
...
@@ -9,11 +9,15 @@ class ApplicationExperiment < Gitlab::Experiment # rubocop:disable Gitlab/Namesp
Feature
.
get
(
feature_flag_name
).
state
!=
:off
# rubocop:disable Gitlab/AvoidFeatureGet
end
def
publish
(
_result
)
def
publish
(
_result
=
nil
)
track
(
:assignment
)
# track that we've assigned a variant for this context
# push the experiment data to the client
Gon
.
push
({
experiment:
{
name
=>
signature
}
},
true
)
if
in_request_cycle?
begin
Gon
.
push
({
experiment:
{
name
=>
signature
}
},
true
)
# push the experiment data to the client
rescue
NoMethodError
# means we're not in the request cycle, and can't add to Gon. Log a warning maybe?
end
end
def
track
(
action
,
**
event_args
)
...
...
@@ -49,12 +53,6 @@ class ApplicationExperiment < Gitlab::Experiment # rubocop:disable Gitlab/Namesp
name
.
tr
(
'/'
,
'_'
)
end
def
in_request_cycle?
# Gon is only accessible when having a request. This will be fixed with
# https://gitlab.com/gitlab-org/gitlab/-/issues/323352
context
.
instance_variable_defined?
(
:@request
)
end
def
resolve_variant_name
case
rollout_strategy
when
:round_robin
...
...
spec/experiments/application_experiment_spec.rb
View file @
2ea64369
...
...
@@ -61,38 +61,19 @@ RSpec.describe ApplicationExperiment, :experiment do
it
"tracks the assignment"
do
expect
(
subject
).
to
receive
(
:track
).
with
(
:assignment
)
subject
.
publish
(
nil
)
end
context
"when inside a request cycle"
do
before
do
subject
.
context
.
instance_variable_set
(
:@request
,
double
(
'Request'
,
headers:
'true'
))
subject
.
publish
end
it
"pushes the experiment knowledge into the client using Gon"
do
expect
(
Gon
).
to
receive
(
:push
).
with
(
{
experiment:
{
'namespaced/stub'
=>
{
# string key because it can be namespaced
experiment:
'namespaced/stub'
,
key:
'86208ac54ca798e11f127e8b23ec396a'
,
variant:
'control'
}
}
},
true
)
expect
(
Gon
).
to
receive
(
:push
).
with
({
experiment:
{
'namespaced/stub'
=>
subject
.
signature
}
},
true
)
subject
.
publish
(
nil
)
end
subject
.
publish
end
context
"when outside a request cycle"
do
it
"does not push to gon when outside request cycle"
do
expect
(
Gon
).
not_to
receive
(
:push
)
it
"handles when Gon raises exceptions (like when it can't be pushed into)"
do
expect
(
Gon
).
to
receive
(
:push
).
and_raise
(
NoMethodError
)
subject
.
publish
(
nil
)
end
expect
{
subject
.
publish
}.
not_to
raise_error
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