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

Revise testing approach #319

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

andyw8
Copy link
Contributor

@andyw8 andyw8 commented Apr 3, 2024

Closes #317

@@ -181,6 +167,10 @@ class ActiveRecord::Base

def hover_on_source(source, position)
with_server(source) do |server, uri|
while RubyLsp::Addon.addons.first.instance_variable_get(:@client).instance_of?(RubyLsp::Rails::NullClient)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're doing the same in #303 but this should be cleaned up.

}

RunnerClient.any_instance.stubs(model: expected_response)
# TODO: not yet working
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vinistock as the server is in a separate process, we can't simply stub schema_dump_path so this is tricky to test. We could have the test modify the app code to include config.active_record.schema_format = :sql, but I'm wondering if it's worth the effort, or if we should just delete this test.

Thread.new { @client = RunnerClient.create_client }
runner_thread = Thread.new { @client = RunnerClient.create_client }
# For tests, we want to wait for the client to be ready
runner_thread.join if ENV["RAILS_ENV"] == "test"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vinistock is this what you had in mind?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(it does slow everything down though, so we'll probably need some way to selectively enable it...)

@andyw8 andyw8 force-pushed the andyw8/revise-testing-approach branch 2 times, most recently from 40a8bef to a03f1f4 Compare May 1, 2024 19:05
@@ -31,7 +31,7 @@ def activate(global_state, message_queue)
@global_state = T.let(global_state, T.nilable(RubyLsp::GlobalState))
$stderr.puts("Activating Ruby LSP Rails addon v#{VERSION}")
# Start booting the real client in a background thread. Until this completes, the client will be a NullClient
Thread.new { @client = RunnerClient.create_client }.join
Thread.new { @client = RunnerClient.create_client }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being fixed in #356

@@ -124,6 +124,8 @@ def baz; end

def generate_definitions_for_source(source, position)
with_server(source) do |server, uri|
sleep(0.1) while RubyLsp::Addon.addons.first.instance_variable_get(:@client).is_a?(NullClient)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being fixed in #356

@@ -238,6 +151,8 @@ class ActiveRecord::Base

def hover_on_source(source, position)
with_server(source) do |server, uri|
sleep(0.1) while RubyLsp::Addon.addons.first.instance_variable_get(:@client).is_a?(NullClient)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same approach as we're using in definition_test, but we should really extract this to provide a better experience for addon developers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we should extract it into a helper. And I also think in that helper we should use addons.find { |addon| addon.name == "Ruby LSP Rails" } instead. I think addons.first will probably break if we someday add another addon to this project's Gemfile as a development dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can extract that part out too, e.g. RubyLsp::Addon.get(...).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does feel like something addons can use during testing 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -146,55 +100,14 @@ class CompositePrimaryKey < ApplicationRecord

**product_id**: integer (PK)

**note**: string
**note**: text
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(the stubbed response was incorrect!)


**created_at**: datetime

**updated_at**: datetime
CONTENT
end

test "handles `db/structure.sql` instead of `db/schema.rb`" do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new approach, these two tests would be awkward, and I don't think really provide much value, so I'm proposing we delete them. (If we did want to keep them, we'd should could them to server_test.rb and adapt them).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think server_test.rb will be a better place for these tests. And since we do test against schema_dump_path being unsupported there, I think it's worth keeping these 2 tests there instead of deleting them.

@andyw8 andyw8 force-pushed the andyw8/revise-testing-approach branch from a03f1f4 to a44dc3f Compare May 1, 2024 19:54
@andyw8 andyw8 changed the title WIP: Revise testing approach Revise testing approach May 1, 2024
@andyw8 andyw8 added the chore Chore task label May 1, 2024
@andyw8 andyw8 marked this pull request as ready for review May 1, 2024 19:54
@andyw8 andyw8 requested a review from a team as a code owner May 1, 2024 19:54
@andyw8 andyw8 requested review from st0012 and vinistock May 1, 2024 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Chore task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Review approach to testing
2 participants