Repository: 1c3t3a/rust-socketio (language: rust)

Issue:
Add a test suite that tests against the official engine/socketio api
There is already the file example/engine.io.js file that could be run via node in order to start up a server. I currently use it to test the client, but not in an automated way.


Discussion / hints:
the current outline is to start a docker-compose instance with the node
socket.io server in one container and the socket.io test code in another one
which will then be executed within GitHub Actions
this is still a work in progress with errors in the build process I'm looking
into the syntax of existing docker and yml files for obvious mistakes
The current suite just runs the socket.io server, it would be nice to add another container to the docker-compose file running the engine.io server.

Fix patch:
diff --git a/.github/workflows/main.yml b/.github/workflows/build.yml
similarity index 66%
rename from .github/workflows/main.yml
rename to .github/workflows/build.yml
index c96dad73..7d0d45cf 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/build.yml
@@ -1,4 +1,4 @@
-name: Rust
+name: Build and code style
 
 on:
   push:
@@ -17,8 +17,6 @@ jobs:
       - uses: actions/checkout@v2
       - name: Build
         run: cargo build --verbose
-      - name: Run tests
-        run: cargo test --verbose --package rust_socketio --lib -- engineio::packet && cargo test --verbose --package rust_socketio --lib -- socketio::packet
       - name: Linting
         run: cargo clippy --verbose
       - name: Check formatting
diff --git a/.gitignore b/.gitignore
index bca8eb6a..bcb3b42f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,5 +2,5 @@
 Cargo.lock
 .vscode
 .idea
-example/node_modules
-example/package-lock.json
+ci/node_modules
+ci/package-lock.json
diff --git a/ci/.dockerignore b/ci/.dockerignore
new file mode 100644
index 00000000..3c3629e6
--- /dev/null
+++ b/ci/.dockerignore
@@ -0,0 +1,1 @@
+node_modules
diff --git a/ci/Dockerfile b/ci/Dockerfile
new file mode 100644
index 00000000..a790cf23
--- /dev/null
+++ b/ci/Dockerfile
@@ -0,0 +1,9 @@
+FROM node:12.18.1
+WORKDIR /test
+COPY . ./
+COPY start_test_server.sh ./
+
+RUN npm install
+
+RUN chmod u+x start_test_server.sh
+CMD ./start_test_server.sh
diff --git a/example/engine-io.js b/ci/engine-io.js
similarity index 100%
rename from example/engine-io.js
rename to ci/engine-io.js
diff --git a/ci/package.json b/ci/package.json
new file mode 100644
index 00000000..f4914ee4
--- /dev/null
+++ b/ci/package.json
@@ -0,0 +1,11 @@
+{
+  "name": "rust-socketio-test",
+  "version": "1.0.0",
+  "description": "A test environment for a socketio client",
+  "author": "Bastian Kersting",
+  "license": "MIT",
+  "dependencies": {
+    "socket.io": "4.0.0",
+    "engine.io": "5.0.0"
+  }
+}
diff --git a/example/socket-io.js b/ci/socket-io.js
similarity index 100%
rename from example/socket-io.js
rename to ci/socket-io.js


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 00000000..a2bc507e
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,37 @@
+name: Test
+
+on:
+  push:
+    branches: [main]
+  pull_request:
+    branches: [main]
+
+env:
+  CARGO_TERM_COLOR: always
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: checkout
+        uses: actions/checkout@v2
+
+      - name: Setup rust environment  
+        uses: actions-rs/toolchain@v1
+        with:
+             profile: minimal
+             toolchain: stable
+             override: true
+
+      - name: Setup docker
+        id: buildx
+        uses: docker/setup-buildx-action@v1
+
+      - name: Build docker container
+        run: |
+          cd ci && docker build -t test_suite:latest .
+          docker run -d -p 4200:4200 -p 4201:4201 test_suite:latest
+
+      - name: Run testsuite
+        run: cargo test --verbose 
diff --git a/ci/start_test_server.sh b/ci/start_test_server.sh
new file mode 100644
index 00000000..c915f12a
--- /dev/null
+++ b/ci/start_test_server.sh
@@ -0,0 +1,29 @@
+echo "Starting test environment"
+DEBUG=* node engine-io.js &
+status=$?
+if [ $status -ne 0 ]; then
+  echo "Failed to start engine.io: $status"
+  exit $status
+fi
+echo "Successfully started engine.io instance"
+
+DEBUG=* node socket-io.js &
+status=$?
+if [ $status -ne 0 ]; then
+  echo "Failed to start socket.io: $status"
+  exit $status
+fi
+echo "Successfully started socket.io instance"
+
+while sleep 60; do
+  ps aux |grep socket |grep -q -v grep
+  PROCESS_1_STATUS=$?
+  ps aux |grep engine |grep -q -v grep
+  PROCESS_2_STATUS=$?
+  # If the greps above find anything, they exit with 0 status
+  # If they are not both 0, then something is wrong
+  if [ $PROCESS_1_STATUS -ne 0 -o $PROCESS_2_STATUS -ne 0 ]; then
+    echo "One of the processes has already exited."
+    exit 1
+  fi
+done