spec: use have_received for statsd increment tests
refs VICE-2034 i notice that some specs use have_receieved instead of increments from the looks of it, these tests look hardier than simply using receive p.s. I really wanted to add the new cop to this commit, but adding a cop is a big effort in and of itself. it will be tackled in the next commit after this one is merged Change-Id: If4a6bde01017abb5ab4c16cdd5d056e4caf1788a Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/273314 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Drake Harper <drake.harper@instructure.com> Reviewed-by: Brian Watson <bwatson@instructure.com> QA-Review: Drake Harper <drake.harper@instructure.com> Product-Review: Drake Harper <drake.harper@instructure.com>
This commit is contained in:
parent
28e682fd6c
commit
75e5d642ec
|
@ -88,7 +88,7 @@ describe GraphQLController do
|
|||
before { allow(InstStatsd::Statsd).to receive(:increment).and_call_original }
|
||||
|
||||
def expect_increment(metric, tags)
|
||||
expect(InstStatsd::Statsd).to receive(:increment).with(metric, tags: tags)
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with(metric, tags: tags)
|
||||
end
|
||||
|
||||
context "for first-party queries" do
|
||||
|
@ -107,11 +107,11 @@ describe GraphQLController do
|
|||
}
|
||||
}
|
||||
GQL
|
||||
post :execute, params: {query: test_query}, format: :json
|
||||
expect_increment("graphql.operation.count", operation_name: 'GetStuff', domain: 'test.host', operation_md5: String)
|
||||
expect_increment("graphql.query.count", operation_name: 'GetStuff', field: 'course', operation_md5: String)
|
||||
expect_increment("graphql.query.count", operation_name: 'GetStuff', field: 'assignment', operation_md5: String)
|
||||
expect_increment("graphql.query.count", operation_name: 'GetStuff', field: 'legacyNode', operation_md5: String)
|
||||
post :execute, params: {query: test_query}, format: :json
|
||||
end
|
||||
|
||||
it "counts unnamed operations" do
|
||||
|
@ -122,10 +122,10 @@ describe GraphQLController do
|
|||
assignment(id: "1") { name }
|
||||
}
|
||||
GQL
|
||||
post :execute, params: {query: test_query}, format: :json
|
||||
expect_increment("graphql.operation.count", operation_name: 'unnamed', domain: 'test.host', operation_md5: String)
|
||||
expect_increment("graphql.query.count", operation_name: 'unnamed', field: 'course', operation_md5: String)
|
||||
expect_increment("graphql.query.count", operation_name: 'unnamed', field: 'assignment', operation_md5: String)
|
||||
post :execute, params: {query: test_query}, format: :json
|
||||
end
|
||||
|
||||
it "counts each mutation top-level field" do
|
||||
|
@ -140,10 +140,10 @@ describe GraphQLController do
|
|||
}
|
||||
}
|
||||
GQL
|
||||
post :execute, params: {query: test_query}, format: :json
|
||||
expect_increment("graphql.operation.count", operation_name: 'unnamed', domain: 'test.host', operation_md5: String)
|
||||
expect_increment("graphql.mutation.count", operation_name: 'unnamed', field: 'createAssignment', operation_md5: String)
|
||||
expect_increment("graphql.mutation.count", operation_name: 'unnamed', field: 'updateAssignment', operation_md5: String)
|
||||
post :execute, params: {query: test_query}, format: :json
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -154,9 +154,9 @@ describe GraphQLController do
|
|||
course(id: "1") { name }
|
||||
}
|
||||
GQL
|
||||
post :execute, params: {query: test_query}, format: :json
|
||||
expect_increment("graphql.operation.count", operation_name: '3rdparty', domain: 'test.host')
|
||||
expect_increment("graphql.query.count", operation_name: '3rdparty', field: 'course')
|
||||
post :execute, params: {query: test_query}, format: :json
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -39,19 +39,19 @@ module Canvas
|
|||
let(:data){ {} }
|
||||
|
||||
it "increments the error level by default" do
|
||||
expect(InstStatsd::Statsd).to receive(:increment) do |key, data|
|
||||
described_class.capture("something", data)
|
||||
expect(InstStatsd::Statsd).to have_received(:increment) do |key, data|
|
||||
expect(key).to eq("errors.error")
|
||||
expect(data[:tags][:category]).to eq("something")
|
||||
end
|
||||
described_class.capture("something", data)
|
||||
end
|
||||
|
||||
it "uses the exception name for the category tag" do
|
||||
expect(InstStatsd::Statsd).to receive(:increment) do |key, data|
|
||||
described_class.capture(StandardError.new, data, :warn)
|
||||
expect(InstStatsd::Statsd).to have_received(:increment) do |key, data|
|
||||
expect(key).to eq("errors.warn")
|
||||
expect(data[:tags][:category]).to eq("StandardError")
|
||||
end
|
||||
described_class.capture(StandardError.new, data, :warn)
|
||||
end
|
||||
|
||||
it "increments the inner exception too" do
|
||||
|
|
|
@ -134,22 +134,27 @@ describe 'Canvas::Twilio' do
|
|||
end
|
||||
|
||||
it 'pings StatsD about outgoing messages' do
|
||||
allow(InstStatsd::Statsd).to receive(:increment)
|
||||
stub_twilio(['+18015550100', '+18015550102'], '+18015550102' => 'CA', '+18015550103' => 'CA', '+18015550104' => 'GB')
|
||||
expect(Canvas::Twilio.client.api.account.messages).to receive(:create).exactly(3).times
|
||||
|
||||
expect(InstStatsd::Statsd).to receive(:increment).with('notifications.twilio.message_sent_from_number.US.+18015550100',
|
||||
short_stat: 'notifications.twilio.message_sent',
|
||||
tags: {country: 'US', number: '+18015550100'}).twice
|
||||
expect(InstStatsd::Statsd).to receive(:increment).with('notifications.twilio.message_sent_from_number.CA.+18015550102',
|
||||
short_stat: 'notifications.twilio.message_sent',
|
||||
tags: {country: 'CA', number: '+18015550102'})
|
||||
expect(InstStatsd::Statsd).to receive(:increment).with('notifications.twilio.no_outbound_numbers_for.GB',
|
||||
short_stat: 'notifications.twilio.no_outbound_numbers',
|
||||
tags: {country: 'GB'})
|
||||
|
||||
Canvas::Twilio.deliver('+18015550101', 'message text')
|
||||
Canvas::Twilio.deliver('+18015550103', 'message text')
|
||||
Canvas::Twilio.deliver('+18015550104', 'message text')
|
||||
expect(InstStatsd::Statsd).to have_received(:increment)
|
||||
.with(
|
||||
'notifications.twilio.message_sent_from_number.US.+18015550100',
|
||||
short_stat: 'notifications.twilio.message_sent',
|
||||
tags: {country: 'US', number: '+18015550100'}
|
||||
).twice
|
||||
expect(InstStatsd::Statsd).to have_received(:increment)
|
||||
.with(
|
||||
'notifications.twilio.message_sent_from_number.CA.+18015550102',
|
||||
short_stat: 'notifications.twilio.message_sent',
|
||||
tags: {country: 'CA', number: '+18015550102'})
|
||||
expect(InstStatsd::Statsd).to have_received(:increment)
|
||||
.with('notifications.twilio.no_outbound_numbers_for.GB',
|
||||
short_stat: 'notifications.twilio.no_outbound_numbers',
|
||||
tags: {country: 'GB'})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,6 +33,7 @@ describe FeatureFlags do
|
|||
before do
|
||||
silence_undefined_feature_flag_errors
|
||||
allow_any_instance_of(User).to receive(:set_default_feature_flags)
|
||||
allow(InstStatsd::Statsd).to receive(:increment)
|
||||
allow(Feature).to receive(:definitions).and_return({
|
||||
'site_admin_feature' => Feature.new(feature: 'site_admin_feature', applies_to: 'SiteAdmin', state: 'allowed'),
|
||||
'root_account_feature' => Feature.new(feature: 'root_account_feature', applies_to: 'RootAccount', state: 'off'),
|
||||
|
@ -58,17 +59,17 @@ describe FeatureFlags do
|
|||
end
|
||||
|
||||
it "should log feature enablement" do
|
||||
expect(InstStatsd::Statsd).to receive(:increment).with("feature_flag_check", tags: {
|
||||
t_sub_account.feature_enabled?(:course_feature)
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with("feature_flag_check", tags: {
|
||||
feature: :course_feature,
|
||||
enabled: 'false'
|
||||
}).exactly(:once)
|
||||
t_sub_account.feature_enabled?(:course_feature)
|
||||
|
||||
expect(InstStatsd::Statsd).to receive(:increment).with("feature_flag_check", tags: {
|
||||
t_sub_account.feature_enabled?(:account_feature)
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with("feature_flag_check", tags: {
|
||||
feature: :account_feature,
|
||||
enabled: 'true'
|
||||
}).exactly(:once)
|
||||
t_sub_account.feature_enabled?(:account_feature)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -199,26 +199,16 @@ describe MicrosoftSync::GraphServiceHttp do
|
|||
end
|
||||
|
||||
it 'increments a "retried" statsd counter' do
|
||||
expect {
|
||||
subject.request(:post, 'foo/bar', body: {hello: 'world'})
|
||||
}.to have_incremented_statsd_stats([
|
||||
{
|
||||
stat: "microsoft_sync.graph_service.retried",
|
||||
options: {
|
||||
tags: {
|
||||
msft_endpoint: 'post_foo',
|
||||
extra_tag: 'abc',
|
||||
status_code: status_code_statsd_tag
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
stat: "microsoft_sync.graph_service.success",
|
||||
options: {
|
||||
tags: {msft_endpoint: 'post_foo', extra_tag: 'abc', status_code: '200'}
|
||||
}
|
||||
}
|
||||
])
|
||||
subject.request(:post, 'foo/bar', body: {hello: 'world'})
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with(
|
||||
"microsoft_sync.graph_service.retried",
|
||||
tags: {msft_endpoint: 'post_foo', extra_tag: 'abc',
|
||||
status_code: status_code_statsd_tag}
|
||||
)
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with(
|
||||
"microsoft_sync.graph_service.success",
|
||||
tags: {msft_endpoint: 'post_foo', extra_tag: 'abc', status_code: '200'}
|
||||
)
|
||||
end
|
||||
|
||||
it 'logs the outcome of each request' do
|
||||
|
@ -237,30 +227,17 @@ describe MicrosoftSync::GraphServiceHttp do
|
|||
let(:requests) { [:bad, :bad] }
|
||||
|
||||
it 'fails and increments "retried" and "error" statsd counters' do
|
||||
expect {
|
||||
subject.request(:post, 'foo/bar')
|
||||
}.to have_incremented_statsd_stats([
|
||||
{
|
||||
stat: "microsoft_sync.graph_service.retried",
|
||||
options: {
|
||||
tags: {
|
||||
msft_endpoint: 'post_foo',
|
||||
extra_tag: 'abc',
|
||||
status_code: status_code_statsd_tag
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
stat: "microsoft_sync.graph_service.intermittent",
|
||||
options: {
|
||||
tags: {
|
||||
msft_endpoint: 'post_foo',
|
||||
extra_tag: 'abc',
|
||||
status_code: status_code_statsd_tag
|
||||
}
|
||||
}
|
||||
}
|
||||
]).and raise_error(error_class)
|
||||
expect { subject.request(:post, 'foo/bar', body: {hello: 'world'}) }.to raise_error(error_class)
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with(
|
||||
"microsoft_sync.graph_service.retried",
|
||||
tags: {msft_endpoint: 'post_foo', extra_tag: 'abc',
|
||||
status_code: status_code_statsd_tag}
|
||||
)
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with(
|
||||
"microsoft_sync.graph_service.intermittent",
|
||||
tags: {msft_endpoint: 'post_foo', extra_tag: 'abc',
|
||||
status_code: status_code_statsd_tag}
|
||||
)
|
||||
end
|
||||
|
||||
it 'logs the outcome of each request' do
|
||||
|
|
|
@ -45,6 +45,10 @@ describe MicrosoftSync::LoginService do
|
|||
context 'when configured' do
|
||||
subject { described_class.new_token('mytenant') }
|
||||
|
||||
before :each do
|
||||
allow(InstStatsd::Statsd).to receive(:increment)
|
||||
end
|
||||
|
||||
context 'when Microsoft returns a response' do
|
||||
before do
|
||||
allow(Canvas::DynamicSettings).to receive(:find).with(any_args).and_call_original
|
||||
|
@ -78,10 +82,11 @@ describe MicrosoftSync::LoginService do
|
|||
it { is_expected.to eq(response_body) }
|
||||
|
||||
it 'increments a statsd metric' do
|
||||
expect(InstStatsd::Statsd).to \
|
||||
receive(:increment).with('microsoft_sync.login_service', tags: {status_code: '200'})
|
||||
.and_call_original
|
||||
subject
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with(
|
||||
'microsoft_sync.login_service',
|
||||
tags: {status_code: '200'}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -90,13 +95,14 @@ describe MicrosoftSync::LoginService do
|
|||
let(:response_body) { {} }
|
||||
|
||||
it 'increments a statsd metric and raises an HTTPInvalidStatus' do
|
||||
expect(InstStatsd::Statsd).to \
|
||||
receive(:increment).with('microsoft_sync.login_service', tags: {status_code: '401'})
|
||||
.and_call_original
|
||||
expect { subject }.to raise_error(
|
||||
MicrosoftSync::Errors::HTTPInvalidStatus,
|
||||
/Login service returned 401 for tenant mytenant/
|
||||
)
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with(
|
||||
'microsoft_sync.login_service',
|
||||
tags: {status_code: '401'}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -150,10 +156,11 @@ describe MicrosoftSync::LoginService do
|
|||
it 'increments a statsd metric and bubbles up the error' do
|
||||
error = SocketError.new
|
||||
expect(HTTParty).to receive(:post).and_raise error
|
||||
expect(InstStatsd::Statsd).to \
|
||||
receive(:increment).with('microsoft_sync.login_service', tags: {status_code: 'error'})
|
||||
.and_call_original
|
||||
expect { subject }.to raise_error(error)
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with(
|
||||
'microsoft_sync.login_service',
|
||||
tags: {status_code: 'error'}
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -369,17 +369,19 @@ describe SIS::CSV::ImportRefactored do
|
|||
expect_any_instance_of(SIS::CSV::ImportRefactored).to receive(:fail_with_error!).once.and_call_original
|
||||
expect_any_instance_of(SIS::CSV::ImportRefactored).to receive(:job_args).once.with(:term, attempt: 1).and_call_original
|
||||
expect_any_instance_of(SIS::CSV::ImportRefactored).to receive(:job_args).once.with(:term, attempt: 2).and_call_original
|
||||
|
||||
csv_importer_double = instance_double(SIS::CSV::TermImporter)
|
||||
allow(SIS::CSV::TermImporter).to receive(:new).and_return(csv_importer_double)
|
||||
allow(csv_importer_double).to receive(:process).and_raise("error")
|
||||
|
||||
process_csv_data("term_id,name,status", "T001,Winter13,active")
|
||||
|
||||
[0, 1, 2].each do |i|
|
||||
expect(InstStatsd::Statsd).to receive(:increment).once.with('sis_parallel_worker',
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).once.with('sis_parallel_worker',
|
||||
tags: { attempt: i, retry: false})
|
||||
expect(InstStatsd::Statsd).to receive(:increment).once.with('sis_parallel_worker',
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).once.with('sis_parallel_worker',
|
||||
tags: { attempt: i, retry: true})
|
||||
end
|
||||
allow_any_instance_of(SIS::CSV::TermImporter).to receive(:process).and_raise("error")
|
||||
process_csv_data(
|
||||
"term_id,name,status",
|
||||
"T001,Winter13,active"
|
||||
)
|
||||
end
|
||||
|
||||
it 'should only run an importer once if successful' do
|
||||
|
|
|
@ -168,16 +168,20 @@ module Turnitin
|
|||
describe "#update_originality_data" do
|
||||
it 'raises an error and sends stat if max attempts are not exceeded' do
|
||||
allow_any_instance_of(subject.class).to receive(:attempt_number).and_return(subject.class.max_attempts-1)
|
||||
allow(InstStatsd::Statsd).to receive(:increment)
|
||||
mock_turnitin_client = double('turnitin_client')
|
||||
allow(mock_turnitin_client).to receive(:scored?).and_return(false)
|
||||
allow(subject).to receive(:turnitin_client).and_return(mock_turnitin_client)
|
||||
submission = lti_assignment.submit_homework(lti_student, attachments:[attachment], submission_type: 'online_upload')
|
||||
expect(InstStatsd::Statsd).to receive(:increment).with("submission_not_scored.account_#{lti_assignment.root_account.global_id}",
|
||||
short_stat: 'submission_not_scored',
|
||||
tags: { root_account_id: lti_assignment.root_account.global_id }).once
|
||||
expect do
|
||||
subject.update_originality_data(submission, attachment.asset_string)
|
||||
end.to raise_error Turnitin::Errors::SubmissionNotScoredError
|
||||
expect(InstStatsd::Statsd).to have_received(:increment)
|
||||
.with(
|
||||
"submission_not_scored.account_#{lti_assignment.root_account.global_id}",
|
||||
short_stat: 'submission_not_scored',
|
||||
tags: { root_account_id: lti_assignment.root_account.global_id }
|
||||
).once
|
||||
end
|
||||
|
||||
it 'sets an error message if max attempts are exceeded' do
|
||||
|
|
|
@ -71,52 +71,38 @@ describe Attachments::Verification do
|
|||
end
|
||||
|
||||
context "verifying a verifier" do
|
||||
before :each do
|
||||
allow(InstStatsd::Statsd).to receive(:increment)
|
||||
end
|
||||
|
||||
it "should verify a legacy verifier for read and download" do
|
||||
expect(InstStatsd::Statsd).to receive(:increment).with("attachments.legacy_verifier_success").twice
|
||||
expect(v.valid_verifier_for_permission?(attachment.uuid, :read)).to eq(true)
|
||||
expect(v.valid_verifier_for_permission?(attachment.uuid, :download)).to eq(true)
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with("attachments.legacy_verifier_success").twice
|
||||
end
|
||||
|
||||
it "accepts the uuid of another copy of the file" do
|
||||
expect(InstStatsd::Statsd).to receive(:increment).with("attachments.related_verifier_success").twice
|
||||
expect(InstStatsd::Statsd).to receive(:increment).with("feature_flag_check", any_args).at_least(:once)
|
||||
clone = attachment.clone_for(course_factory)
|
||||
clone.save!
|
||||
v2 = Attachments::Verification.new(clone)
|
||||
expect(v2.valid_verifier_for_permission?(attachment.uuid, :read)).to eq true
|
||||
expect(v2.valid_verifier_for_permission?(attachment.uuid, :download)).to eq true
|
||||
end
|
||||
|
||||
it "should return false on an expired verifier" do
|
||||
expect(CanvasSecurity).to receive(:decode_jwt).with("token").and_raise(CanvasSecurity::TokenExpired)
|
||||
|
||||
result = true
|
||||
expect {
|
||||
result = v.valid_verifier_for_permission?("token", :read)
|
||||
}.to have_incremented_statsd_stat("attachments.token_verifier_expired")
|
||||
expect(result).to eq(false)
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with("attachments.related_verifier_success").twice
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with("feature_flag_check", any_args).at_least(:once)
|
||||
end
|
||||
|
||||
it "should return false on an invalid verifier" do
|
||||
expect(CanvasSecurity).to receive(:decode_jwt).with("token").and_raise(CanvasSecurity::InvalidToken)
|
||||
|
||||
result = true
|
||||
expect {
|
||||
result = v.valid_verifier_for_permission?("token", :read)
|
||||
}.to have_incremented_statsd_stat("attachments.token_verifier_invalid")
|
||||
expect(result).to eq(false)
|
||||
expect(v.valid_verifier_for_permission?("token", :read)).to eq(false)
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with("attachments.token_verifier_invalid")
|
||||
end
|
||||
|
||||
it "should return false on token id mismatch" do
|
||||
expect(CanvasSecurity).to receive(:decode_jwt).with("token").and_return({
|
||||
id: attachment.global_id + 1
|
||||
})
|
||||
|
||||
result = true
|
||||
expect {
|
||||
result = v.valid_verifier_for_permission?("token", :read)
|
||||
}.to have_incremented_statsd_stat("attachments.token_verifier_id_mismatch")
|
||||
expect(result).to eq(false)
|
||||
expect(v.valid_verifier_for_permission?("token", :read)).to eq(false)
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with("attachments.token_verifier_id_mismatch")
|
||||
end
|
||||
|
||||
it "should not let a student download an attachment that's locked" do
|
||||
|
@ -126,11 +112,10 @@ describe Attachments::Verification do
|
|||
expect(CanvasSecurity).to receive(:decode_jwt).with("token").and_return({
|
||||
id: att2.global_id, user_id: student.global_id
|
||||
}).twice
|
||||
expect(InstStatsd::Statsd).to receive(:increment).with("attachments.token_verifier_success").twice
|
||||
expect(InstStatsd::Statsd).to receive(:increment).with("feature_flag_check", any_args).at_least(:once)
|
||||
|
||||
expect(v2.valid_verifier_for_permission?("token", :read)).to eq(true)
|
||||
expect(v2.valid_verifier_for_permission?("token", :download)).to eq(false)
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with("attachments.token_verifier_success").twice
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with("feature_flag_check", any_args).at_least(:once)
|
||||
end
|
||||
|
||||
it "follows custom permissions" do
|
||||
|
|
|
@ -74,13 +74,13 @@ describe AuthenticationProvider::LDAP do
|
|||
allow(@aac).to receive(:account_id).and_return(1)
|
||||
allow(@aac).to receive(:global_id).and_return(2)
|
||||
allow(@aac).to receive(:should_send_to_statsd?).and_return(true)
|
||||
allow(InstStatsd::Statsd).to receive(:increment)
|
||||
end
|
||||
|
||||
it "should send to statsd on success" do
|
||||
allow(@ldap).to receive(:bind_as).and_return(true)
|
||||
expect {
|
||||
@aac.ldap_bind_result('user', 'pass')
|
||||
}.to have_incremented_statsd_stat(
|
||||
@aac.ldap_bind_result('user', 'pass')
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with(
|
||||
"#{@aac.send(:statsd_prefix)}.ldap_success",
|
||||
short_stat: "ldap_success",
|
||||
tags: {account_id: Shard.global_id_for(@aac.account_id), auth_provider_id: @aac.global_id}
|
||||
|
@ -89,9 +89,8 @@ describe AuthenticationProvider::LDAP do
|
|||
|
||||
it "should send to statsd on failure" do
|
||||
allow(@ldap).to receive(:bind_as).and_return(false)
|
||||
expect {
|
||||
@aac.ldap_bind_result('user', 'pass')
|
||||
}.to have_incremented_statsd_stat(
|
||||
@aac.ldap_bind_result('user', 'pass')
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with(
|
||||
"#{@aac.send(:statsd_prefix)}.ldap_failure",
|
||||
short_stat: "ldap_failure",
|
||||
tags: {account_id: Shard.global_id_for(@aac.account_id), auth_provider_id: @aac.global_id}
|
||||
|
@ -100,28 +99,28 @@ describe AuthenticationProvider::LDAP do
|
|||
|
||||
it "should send to statsd on timeout" do
|
||||
allow(@ldap).to receive(:bind_as).and_raise(Timeout::Error)
|
||||
expect {
|
||||
@aac.ldap_bind_result('user', 'pass')
|
||||
}.to have_incremented_statsd_stat("#{@aac.send(:statsd_prefix)}.ldap_timeout", {
|
||||
@aac.ldap_bind_result('user', 'pass')
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with(
|
||||
"#{@aac.send(:statsd_prefix)}.ldap_timeout",
|
||||
short_stat: "ldap_timeout",
|
||||
tags: {
|
||||
account_id: Shard.global_id_for(@aac.account_id),
|
||||
auth_provider_id: @aac.global_id
|
||||
}
|
||||
})
|
||||
)
|
||||
end
|
||||
|
||||
it "should send to statsd on exception" do
|
||||
allow(@ldap).to receive(:bind_as).and_raise(StandardError)
|
||||
expect {
|
||||
@aac.ldap_bind_result('user', 'pass')
|
||||
}.to have_incremented_statsd_stat("#{@aac.send(:statsd_prefix)}.ldap_error", {
|
||||
@aac.ldap_bind_result('user', 'pass')
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with(
|
||||
"#{@aac.send(:statsd_prefix)}.ldap_error",
|
||||
short_stat: "ldap_error",
|
||||
tags: {
|
||||
account_id: Shard.global_id_for(@aac.account_id),
|
||||
auth_provider_id: @aac.global_id
|
||||
}
|
||||
})
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -124,25 +124,16 @@ describe BounceNotificationProcessor do
|
|||
expect(queue).to expectation
|
||||
allow(bnp).to receive(:bounce_queue).and_return(queue)
|
||||
allow(CommunicationChannel).to receive(:bounce_for_path)
|
||||
|
||||
expect { bnp.process }.to have_incremented_statsd_stats([
|
||||
{
|
||||
stat: 'bounce_notification_processor.processed.transient',
|
||||
count: 1
|
||||
},
|
||||
{
|
||||
stat: 'bounce_notification_processor.processed.no_bounce',
|
||||
count: 2
|
||||
},
|
||||
{
|
||||
stat: 'bounce_notification_processor.processed.suppression',
|
||||
count: 3
|
||||
},
|
||||
{
|
||||
stat: 'bounce_notification_processor.processed.permanent',
|
||||
count: 4
|
||||
}
|
||||
])
|
||||
allow(InstStatsd::Statsd).to receive(:increment)
|
||||
bnp.process
|
||||
expect(InstStatsd::Statsd).to have_received(:increment)
|
||||
.with('bounce_notification_processor.processed.transient').once
|
||||
expect(InstStatsd::Statsd).to have_received(:increment)
|
||||
.with('bounce_notification_processor.processed.no_bounce').twice
|
||||
expect(InstStatsd::Statsd).to have_received(:increment)
|
||||
.with('bounce_notification_processor.processed.suppression').exactly(3).times
|
||||
expect(InstStatsd::Statsd).to have_received(:increment)
|
||||
.with('bounce_notification_processor.processed.permanent').exactly(4).times
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -737,6 +737,7 @@ describe CommunicationChannel do
|
|||
|
||||
it "sends directly via SMS if configured" do
|
||||
expect(cc.e164_path).to eq '+18015555555'
|
||||
allow(InstStatsd::Statsd).to receive(:increment)
|
||||
account = double()
|
||||
allow(account).to receive(:feature_enabled?).and_return(true)
|
||||
allow(account).to receive(:global_id).and_return('totes_an_ID')
|
||||
|
@ -748,24 +749,22 @@ describe CommunicationChannel do
|
|||
true
|
||||
)
|
||||
expect(cc).to receive(:send_otp_via_sms_gateway!).never
|
||||
expect {
|
||||
cc.send_otp!('123456', account)
|
||||
}.to have_incremented_statsd_stats([
|
||||
cc.send_otp!('123456', account)
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with(
|
||||
"message.deliver.sms.one_time_password",
|
||||
{
|
||||
stat: "message.deliver.sms.one_time_password",
|
||||
options: {
|
||||
short_stat: "message.deliver",
|
||||
tags: {path_type: "sms", notification_name: 'one_time_password'}
|
||||
}
|
||||
},
|
||||
{
|
||||
stat: "message.deliver.sms.totes_an_ID",
|
||||
options: {
|
||||
short_stat: "message.deliver_per_account",
|
||||
tags: {path_type: "sms", root_account_id: 'totes_an_ID'}
|
||||
}
|
||||
short_stat: "message.deliver",
|
||||
tags: { path_type: "sms", notification_name: 'one_time_password' }
|
||||
}
|
||||
])
|
||||
)
|
||||
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with(
|
||||
"message.deliver.sms.totes_an_ID",
|
||||
{
|
||||
short_stat: "message.deliver_per_account",
|
||||
tags: { path_type: "sms", root_account_id: 'totes_an_ID' }
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
it "sends via email if not configured" do
|
||||
|
|
|
@ -195,14 +195,17 @@ describe GroupAndMembershipImporter do
|
|||
end
|
||||
|
||||
it 'should log stat on new groups' do
|
||||
expect {
|
||||
import_csv_data(%{user_id,group_name
|
||||
user_4,anugroup})
|
||||
}.to have_incremented_statsd_stat('groups.auto_create', tags: {
|
||||
split_type: 'csv',
|
||||
root_account_id: gc1.root_account&.global_id,
|
||||
root_account_name: gc1.root_account&.name
|
||||
})
|
||||
allow(InstStatsd::Statsd).to receive(:increment)
|
||||
import_csv_data(%{user_id,group_name
|
||||
user_4,anugroup})
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with(
|
||||
"groups.auto_create",
|
||||
tags: {
|
||||
split_type: 'csv',
|
||||
root_account_id: gc1.root_account&.global_id,
|
||||
root_account_name: gc1.root_account&.name
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -115,6 +115,7 @@ describe LearningOutcome do
|
|||
end
|
||||
|
||||
it "adding outcomes to a rubric should increment datadog counter" do
|
||||
allow(InstStatsd::Statsd).to receive(:increment)
|
||||
@rubric = Rubric.new(:context => @course)
|
||||
@rubric.data = [
|
||||
{
|
||||
|
@ -138,9 +139,9 @@ describe LearningOutcome do
|
|||
:learning_outcome_id => @outcome.id
|
||||
}
|
||||
]
|
||||
expect {
|
||||
@rubric.save!
|
||||
}.to have_incremented_statsd_stat('learning_outcome.align')
|
||||
@rubric.save!
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with('learning_outcome.align')
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with("feature_flag_check", any_args).at_least(:once)
|
||||
end
|
||||
|
||||
it "should allow learning outcome rows in the rubric" do
|
||||
|
|
|
@ -72,15 +72,16 @@ describe Mailer do
|
|||
end
|
||||
|
||||
it 'sends stat to stat service' do
|
||||
allow(InstStatsd::Statsd).to receive(:increment)
|
||||
message = message_model(to: "someemail@example.com")
|
||||
mail = Mailer.create_message(message)
|
||||
expect(mail).to receive(:deliver_now)
|
||||
expect {
|
||||
Mailer.deliver(mail)
|
||||
}.to have_incremented_statsd_stat('message.deliver', {
|
||||
short_stat: "message.deliver",
|
||||
tags: { path_type: "mailer_emails", notification_name: 'mailer_delivery' }
|
||||
})
|
||||
Mailer.deliver(mail)
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with(
|
||||
"message.deliver",
|
||||
{ short_stat: "message.deliver",
|
||||
tags: { path_type: "mailer_emails", notification_name: 'mailer_delivery' } }
|
||||
)
|
||||
end
|
||||
|
||||
it 'calls the notification service if configured' do
|
||||
|
|
|
@ -313,6 +313,7 @@ describe Message do
|
|||
end
|
||||
|
||||
it "logs stats on deliver" do
|
||||
allow(InstStatsd::Statsd).to receive(:increment)
|
||||
account = account_model
|
||||
@message = message_model(dispatch_at: Time.now - 1,
|
||||
notification_name: 'my_name',
|
||||
|
@ -322,26 +323,23 @@ describe Message do
|
|||
path_type: 'email',
|
||||
user: @user,
|
||||
root_account: account)
|
||||
|
||||
expect(@message).to receive(:dispatch).and_return(true)
|
||||
expect {
|
||||
@message.deliver
|
||||
}.to have_incremented_statsd_stats([
|
||||
@message.deliver
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with(
|
||||
"message.deliver.email.my_name",
|
||||
{
|
||||
stat: "message.deliver.email.my_name",
|
||||
options: {
|
||||
short_stat: "message.deliver",
|
||||
tags: {path_type: "email", notification_name: 'my_name'}
|
||||
}
|
||||
},
|
||||
{
|
||||
stat: "message.deliver.email.#{@message.root_account.global_id}",
|
||||
options: {
|
||||
short_stat: "message.deliver_per_account",
|
||||
tags: {path_type: "email", root_account_id: @message.root_account.global_id}
|
||||
}
|
||||
short_stat: "message.deliver",
|
||||
tags: {path_type: "email", notification_name: 'my_name'}
|
||||
}
|
||||
])
|
||||
)
|
||||
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with(
|
||||
"message.deliver.email.#{@message.root_account.global_id}",
|
||||
{
|
||||
short_stat: "message.deliver_per_account",
|
||||
tags: {path_type: "email", root_account_id: @message.root_account.global_id}
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
context 'push' do
|
||||
|
|
|
@ -338,21 +338,22 @@ describe RubricAssessment do
|
|||
end
|
||||
|
||||
it 'assessing a rubric with outcome criterion should increment datadog counter' do
|
||||
allow(InstStatsd::Statsd).to receive(:increment)
|
||||
@outcome.update!(data: nil)
|
||||
criterion_id = "criterion_#{@rubric.data[0][:id]}".to_sym
|
||||
expect {
|
||||
@association.assess({
|
||||
:user => @student,
|
||||
:assessor => @teacher,
|
||||
:artifact => @assignment.find_or_create_submission(@student),
|
||||
:assessment => {
|
||||
:assessment_type => 'grading',
|
||||
criterion_id => {
|
||||
:points => '3'
|
||||
}
|
||||
@association.assess({
|
||||
:user => @student,
|
||||
:assessor => @teacher,
|
||||
:artifact => @assignment.find_or_create_submission(@student),
|
||||
:assessment => {
|
||||
:assessment_type => 'grading',
|
||||
criterion_id => {
|
||||
:points => '3'
|
||||
}
|
||||
})
|
||||
}.to have_incremented_statsd_stat('learning_outcome_result.create')
|
||||
}
|
||||
})
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with("feature_flag_check", any_args).at_least(:once)
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with('learning_outcome_result.create')
|
||||
end
|
||||
|
||||
it 'should use default ratings for scoring' do
|
||||
|
|
|
@ -97,10 +97,9 @@ describe SisBatch do
|
|||
|
||||
it 'should log stats' do
|
||||
allow(InstStatsd::Statsd).to receive(:increment)
|
||||
expect(InstStatsd::Statsd).to receive(:increment).with("sis_batch_completed", tags: { failed: false })
|
||||
process_csv_data([%{user_id,login_id,status
|
||||
user_1,user_1,active}])
|
||||
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with("sis_batch_completed", tags: { failed: false })
|
||||
end
|
||||
|
||||
it 'should restore linked observers when restoring enrollments' do
|
||||
|
@ -117,12 +116,11 @@ describe SisBatch do
|
|||
expect(student_enrollment.reload.workflow_state).to eq 'deleted'
|
||||
expect(observer_enrollment.reload.workflow_state).to eq 'deleted'
|
||||
tags = { undelete_only: false, unconclude_only: false, batch_mode: false }
|
||||
expect(InstStatsd::Statsd).to receive(:increment).with("sis_batch_restored", tags: tags)
|
||||
|
||||
batch.restore_states_for_batch
|
||||
run_jobs
|
||||
expect(student_enrollment.reload.workflow_state).to eq 'active'
|
||||
expect(observer_enrollment.reload.workflow_state).to eq 'active'
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with("sis_batch_restored", tags: tags)
|
||||
end
|
||||
|
||||
it 'should create new linked observer enrollments when restoring enrollments' do
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
#
|
||||
# Copyright (C) 2021 - present Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
RSpec::Matchers.define :have_incremented_statsd_stat do |stat, *options|
|
||||
match do |action|
|
||||
allow(InstStatsd::Statsd).to receive(:increment).and_call_original
|
||||
# expect increment to be called with stat and options if provided
|
||||
expect(InstStatsd::Statsd).to(
|
||||
receive(:increment).with(*[stat, *options].compact),
|
||||
"expected stat: #{stat} with options: #{options} to be incremented but wasn't"
|
||||
)
|
||||
action.call
|
||||
RSpec::Mocks.verify # run mock verifications
|
||||
end
|
||||
|
||||
supports_block_expectations
|
||||
end
|
|
@ -1,38 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
#
|
||||
# Copyright (C) 2021 - present Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
RSpec::Matchers.define :have_incremented_statsd_stats do |stats|
|
||||
match do |action|
|
||||
allow(InstStatsd::Statsd).to receive(:increment).and_call_original
|
||||
stats.each do |obj|
|
||||
stat = obj[:stat]
|
||||
options = obj[:options]
|
||||
count = obj[:count] || 1
|
||||
# expect increment to be called with stat and options if provided
|
||||
expect(InstStatsd::Statsd).to(
|
||||
receive(:increment).with(*[stat, options].compact).exactly(count).times,
|
||||
"expected stat: #{stat} with options: #{options} to be incremented exactly #{count} times but wasn't"
|
||||
)
|
||||
end
|
||||
action.call
|
||||
RSpec::Mocks.verify # run mock verifications
|
||||
end
|
||||
|
||||
supports_block_expectations
|
||||
end
|
Loading…
Reference in New Issue