Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not enqueuing test action in real queue #237

Merged
merged 1 commit into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/segment/analytics/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ def enqueue(action)
# add our request id for tracing purposes
action[:messageId] ||= uid

test_queue << action if @test
if @test
test_queue << action
return true
end

if @queue.length < @max_queue_size
@queue << action
Expand All @@ -170,9 +173,7 @@ def enqueue(action)
true
else
logger.warn(
'Queue is full, dropping events. The :max_queue_size ' \
'configuration parameter can be increased to prevent this from ' \
'happening.'
'Queue is full, dropping events. The :max_queue_size configuration parameter can be increased to prevent this from happening.'
)
false
end
Expand Down
15 changes: 15 additions & 0 deletions spec/segment/analytics/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,21 @@ class Analytics
expect(message[:integrations][:Salesforce]).to eq(false)
end
end

it 'does not enqueue the action in test mode' do
client.instance_variable_set(:@test, true)
client.test_queue
test_queue = client.instance_variable_get(:@test_queue)

%i[track screen page group identify alias].each do |s|
old_test_queue_size = test_queue.count
queue_size = queue.length
client.send(s, data)

expect(queue.length).to eq(queue_size) # The "real" queue size should not change in test mode
expect(test_queue.count).to_not eq(old_test_queue_size) # The "test" queue size should change in test mode
end
end
end
end
end
Expand Down