-
Notifications
You must be signed in to change notification settings - Fork 25
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
add test cases to sequel gem implementation #412
Conversation
Signed-off-by: arjun-rajappa <[email protected]>
0e8e09f
to
05ad11f
Compare
Signed-off-by: arjun-rajappa <[email protected]>
Signed-off-by: arjun-rajappa <[email protected]>
Signed-off-by: arjun-rajappa <[email protected]>
Signed-off-by: arjun-rajappa <[email protected]>
test/instrumentation/sequel_test.rb
Outdated
@@ -0,0 +1,115 @@ | |||
# (c) Copyright IBM Corp. 2024 | |||
# (c) Copyright Instana Inc. 2024 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need Instana Inc.
on new files anymore.
test/instrumentation/sequel_test.rb
Outdated
db_url = ENV['DATABASE_URL'].sub("sqlite3", "sqlite") | ||
@db = Sequel.connect(db_url) | ||
|
||
DummyMigration.apply(@db, :up) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the addedd benefit of using this DummyMigration
class over simply creating the table?
@db.create_table :blocks do
String :name
String :color
end
assert_equal 2, spans.length | ||
span = find_first_span_by_name(spans, :sequel) | ||
data = span[:data][:sequel] | ||
assert data[:sql].start_with?('INSERT INTO') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also be checked: assert_equal 0, span[:ec]
Furthermore we should also ensure that the insert was successful.
test/instrumentation/sequel_test.rb
Outdated
|
||
def test_raw | ||
Instana::Tracer.start_or_continue_trace(:sequel_test, {}) do | ||
@db.execute('SELECT 1') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@db.execute
is not even publicly documented. According to the docs, @db.run
is the idiomatic way to execute arbitrary statements.
And while I am no SQL expert, I don't think it is particularly likely that customers would write such queries, I think more likely scenarios, that they query the CURRENT_TIMESTAMP
number, or a random()
number;
assert_equal 2, spans.length | ||
span = find_first_span_by_name(spans, :sequel) | ||
data = span[:data][:sequel] | ||
assert 'SELECT 1', data[:sql] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert_equal 0, span[:ec]. Was the op successful?
spans = ::Instana.processor.queued_spans | ||
assert_equal 2, spans.length | ||
span = find_first_span_by_name(spans, :sequel) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check that the execution has indeed failed.
test/instrumentation/sequel_test.rb
Outdated
def test_raw_error | ||
assert_raises Sequel::DatabaseError do | ||
Instana::Tracer.start_or_continue_trace(:sequel_test, {}) do | ||
@db.execute('INVALID') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@db.execute
is not even publicly documented. According to the docs, @db.run
is the idiomatic way to execute arbitrary statements.
Signed-off-by: arjun-rajappa <[email protected]>
Signed-off-by: arjun-rajappa <[email protected]>
Adding support for a new gem - Sequel
Add test cases