anycable / actioncable-next

Next-gen Action Cable implementation
MIT License
21 stars 2 forks source link

Expose server instance #5

Open ioquatix opened 3 hours ago

ioquatix commented 3 hours ago

ActionCable.server in Channel instances is a code smell. It makes testing more difficult than it should be (parallel tests might have more than one server).

I think Connection should expose server, e.g.

class TestChannel < ActionCable::Channel::Base
    def broadcast(data)
        # ActionCable.server.broadcast ... # bad!!!
        self.server.broadcast("testing-#{test_id}", data)
    end

    private def server
        @connection.send(:server)
    end

I don't think we should encourage users to write ActionCable.server except as a last resort.

lattaai13 commented 3 hours ago

Hello, I tried to solve the issue.

This is what I did:

Modified Connection::Base to expose server as a public method. Updated Channel::Base to access server through the connection. This change allows channels to access the server without using ActionCable.server, making testing easier and avoiding potential issues with parallel tests.

You can review changes in this commit: https://github.com/lattaai13/anycable-actioncable-next-5/commit/57114377e376dcc993d28e7d48020f4929735ebb.

[!CAUTION] Disclaimer: The commit was created by Latta AI and you should never copy paste this code before you check the correctness of generated code. Solution might not be complete, you should use this code as an inspiration only.


This issue was tried to solve for free by Latta AI - https://latta.ai/ourmission

If you no longer want Latta AI to attempt solving issues on your repository, you can block this account.