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

testkit-backend: Add support for testing driver in browser #798

Merged
merged 12 commits into from
Nov 18, 2021

Conversation

bigmontz
Copy link
Contributor

@bigmontz bigmontz commented Oct 26, 2021

The initial implementation of the testkit-backend is NodeJS only which is not an issue for the time being. However, It starts to be problematic with new features being implemented test driven using testkit as the source of tests. First, the time for run all the suite increased a lot with the number of tests added and the need of keeping the some integration tests to not let browser uncovered. Second, the driver running in browser was not being tested with the same rigour as in Nodejs.

The following changes were done with the intent to support testkit tests in Browser.

Refactoring

The logic of reading and writing in the socket, call the handlers and parse the messages were mixed in the Backend class. This makes difficult to add different protocols, channel implementation or controllers to the backend.

The goal of this change is separate this three concerns in Channel, Controller and Protocol with the Backend class as the glue between these concepts. New implementations of the Controller could enable this backend to test the driver running in the browser without have to change the logic of parsing the messages between testkit and testkit-backend, for instance.

Supporting Browser

The first step for supporting testkit in browser was creating a web socket server to redirect the requests to a client. RemoteController is the class responsible for it, it acts like a proxy redirecting the requests and responses. In the other side, WebSocketChannel is responsible for managing the messages exchanges between browser-backend and nodejs-backend in the browser side.

The main function glued everything together using env variables for selecting the correct channel and controller.

A bit more of structure had to be taking in place for bundle testkit for running in browser. The bundle is supported by rollup and defined in rollup.config.js, this runs during the build and the outcome is stored in public/index.js. The following env variables are defined during the browser build to enforce the correct configuration:

  • TEST_ENVIRONMENT = "LOCAL"
  • CHANNEL_TYPE = "WEBSOCKET"
  • BACKEND_PORT = WEB_SERVER_PORT (or 8000 if nothing is set in WEB_SERVER_PORT)

The last thing done during the browser build process is done by some replacements done in the package.json, the ./src/controller/remote.js and ./src/channel/socket.js are replaced by their interfaces since the some modules used in this files are really tricky to support in browser and they are not need at browser.

After we have the browser bundle done, we need to server it. It is done by the RemoteController as well.

At this point, you can run TEST_ENVIRONMENT=REMOTE npm run start-testkit-backend and open your favorite browser in localhost:8000 for running testkit tests in browser.

Glue everything in Testkit

Last but not least, the testkit scripts were adapt to use the environment TEST_DRIVER_BROWSER to decide if the tests should be run in browser and in nodejs. Integration tests were segregated for running only the ones needed for the environment under tests.

backend.py is responsible for configuring correctly the backend using the env-variables and also for starting a headless browser with the browser-backend url.

IMPORTANTE NOTE

This version doesn't support TLS_TESTS and STUB_TESTS since the mock servers doesn't support websocket yet

@bigmontz bigmontz changed the title testkit-backend: Separate the socket connection, protocol and controller testkit-backend: Decoupling socket connection, protocol and controller/request handler Oct 26, 2021
@bigmontz bigmontz marked this pull request as ready for review October 28, 2021 16:16
The logic of reading and writing in the socket, call the handlers and parse the messages were mixed in the Backend class. This makes difficult to add different protocols, socket implementation or controllers to the backend.

The goal of this change is separate this three concerns in `SocketServer`, `Controller` and `Protocol` with the `Backend` class as the glue between these concepts. New implementations of the `Controller` could enable this backend to test the driver running in the browser without have to change the logic of parsing the messages between testkit and testkit-backend, for instance.
@bigmontz bigmontz changed the title testkit-backend: Decoupling socket connection, protocol and controller/request handler testkit-backend: Add support for testing driver in browser Nov 15, 2021
Copy link
Member

@robsdedude robsdedude left a comment

Choose a reason for hiding this comment

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

Quite a few comments. None of them are a deal-breaker. Mainly typos and question.

Great PR!!!

🚀

packages/testkit-backend/package.json Show resolved Hide resolved
packages/testkit-backend/src/channel/socket.js Outdated Show resolved Hide resolved
packages/testkit-backend/src/channel/socket.js Outdated Show resolved Hide resolved
packages/testkit-backend/src/index.js Outdated Show resolved Hide resolved
testkit/backend.py Outdated Show resolved Hide resolved
testkit/backend.py Outdated Show resolved Hide resolved
testkit/integration.py Outdated Show resolved Hide resolved
testkit/stress.py Outdated Show resolved Hide resolved
@bigmontz bigmontz merged commit 2b53303 into neo4j:4.4 Nov 18, 2021
@bigmontz bigmontz deleted the 4.4-new-backend branch November 18, 2021 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants