diff --git a/.github/workflows/cross_build.yml b/.github/workflows/cross_build.yml new file mode 100644 index 00000000..c2103a1e --- /dev/null +++ b/.github/workflows/cross_build.yml @@ -0,0 +1,57 @@ +name: cross-build + +on: + push: + branches: + - improve-and-fix-workflow +# pull_request: +# types: [closed] +# branches: +# - main + +jobs: + wait-for-other-workflow: + name: Wait for Other Workflow + runs-on: ubuntu-latest + steps: + - name: Wait for Other Workflow to Complete + run: "echo 'Waiting for other workflow to complete...'" + + build: + if: github.event.pull_request.merged == true + name: Build C release for ${{ matrix.os.name }} + strategy: + matrix: + os: + - name: ubuntu + lib: libsurrealdb_c.so + - name: macos + lib: libsurrealdb_c.dylib + - name: windows + lib: surrealdb_c.dll + runs-on: ${{ format('{0}-latest', matrix.os.name) }} + steps: + - name: Checkout Surreal C lib + uses: actions/checkout@v3 + with: + repository: surrealdb/surrealdb.c + + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Build Rust library + run: cargo build --release + + - name: Archive library + run: | + mkdir -p dist/${{ matrix.os.name }} + cp target/release/${{ matrix.os.lib }} dist/${{ matrix.os.name }}/${{ matrix.os.lib }} + + - name: Upload build artifacts + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.os.name }}-build + path: dist/${{ matrix.os.name }} diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index fea55156..e9adc971 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -1,8 +1,10 @@ name: unit-tests on: + push: + branches: + - main pull_request: - # push: branches: - "*" @@ -10,24 +12,28 @@ jobs: run-unit-tests: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - python-version: [ "3.7", "3.8", "3.9", "3.10" ] - + python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ] + surrealdb-version: ["v2.0.0", "v2.1.1", "v2.1.2"] # Issue with v2.1.0 + name: Run unit test SurrealDB ${{ matrix.surrealdb-version }} - Python Version ${{ matrix.python-version }} steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - name: Build for tests - run: | - python tests/scripts/local_build_ci.py - pip install docker - pip install requests -# docker-compose build -# docker-compose up -d -# sleep 2 - - - name: Run Tests - run: sh scripts/run_tests.sh + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Download and install surrealdb + run: curl -sSf https://install.surrealdb.com | sh -s -- --version ${{ matrix.surrealdb-version }} + + - name: Start surrealdb + run: surreal start memory -u root -p root --log trace & sleep 5 & + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Run unit tests + env: + SURREALDB_URL: "http://localhost:8000" + run: python -m unittest discover -s tests + + diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..ddaa66fc --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +.PHONY: test test_versions + +test: + python -m unittest discover -s tests + +test_versions: + python tests/scripts/runner.py diff --git a/requirements.txt b/requirements.txt index 29208180..db002b1c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ cbor2==5.6.5 -docker_py==1.10.6 +docker==7.1.0 Requests==2.32.3 -setuptools==63.2.0 setuptools==65.5.1 setuptools_rust==1.6.0 websockets==14.1 diff --git a/surrealdb/connection.py b/surrealdb/connection.py index 5279c2ae..ad8c75e3 100644 --- a/surrealdb/connection.py +++ b/surrealdb/connection.py @@ -25,6 +25,7 @@ class RequestData: class Connection: _queues: Dict[int, dict] + _locks: Dict[int, threading.Lock] _namespace: str | None = None _database: str | None = None _auth_token: str | None = None diff --git a/tests/integration/async/test_live.py b/tests/integration/async/test_live.py index ddec1f7e..3989e6fd 100644 --- a/tests/integration/async/test_live.py +++ b/tests/integration/async/test_live.py @@ -18,15 +18,14 @@ async def asyncSetUp(self): await self.db.sign_in("root", "root") async def test_live(self): - live_id = await self.db.live(Table("users")) - print("Live id: ", live_id) + if self.params.protocol.lower() == "ws": + live_id = await self.db.live(Table("users")) + live_queue = await self.db.live_notifications(live_id) - live_queue = await self.db.live_notifications(live_id) + await self.db.query("CREATE users;") - await self.db.query("CREATE users;") - - notification_data = await asyncio.wait_for(live_queue.get(), 10) # Set timeout - self.assertEqual(notification_data.get("id"), live_id) - self.assertEqual(notification_data.get("action"), "CREATE") + notification_data = await asyncio.wait_for(live_queue.get(), 10) # Set timeout + self.assertEqual(notification_data.get("id"), live_id) + self.assertEqual(notification_data.get("action"), "CREATE") diff --git a/tests/integration/async/test_update.py b/tests/integration/async/test_update.py index 5d501086..912d09c5 100644 --- a/tests/integration/async/test_update.py +++ b/tests/integration/async/test_update.py @@ -2,7 +2,6 @@ Tests the Update operation of the AsyncSurrealDB class with query and update function. """ -import asyncio from typing import List from unittest import IsolatedAsyncioTestCase, main diff --git a/tests/integration/blocking/test_auth.py b/tests/integration/blocking/test_auth.py index 31851d1a..94f45b51 100644 --- a/tests/integration/blocking/test_auth.py +++ b/tests/integration/blocking/test_auth.py @@ -2,7 +2,6 @@ Handles the integration tests for logging into the database using blocking operations. """ -import os from unittest import TestCase, main from surrealdb import SurrealDB diff --git a/tests/integration/blocking/test_live.py b/tests/integration/blocking/test_live.py index dcb27ddf..e362b2d7 100644 --- a/tests/integration/blocking/test_live.py +++ b/tests/integration/blocking/test_live.py @@ -18,16 +18,15 @@ def setUp(self): self.db.sign_in("root", "root") def test_live(self): - live_id = self.db.live(Table("users")) - print("Live id: ", live_id) + if self.params.protocol.lower() == "ws": + live_id = self.db.live(Table("users")) + live_queue = self.db.live_notifications(live_id) - live_queue = self.db.live_notifications(live_id) + self.db.query("CREATE users;") - self.db.query("CREATE users;") - - loop_manager = AsyncioRuntime() - notification_data = loop_manager.loop.run_until_complete(live_queue.get()) - self.assertEqual(notification_data.get("id"), live_id) - self.assertEqual(notification_data.get("action"), "CREATE") + loop_manager = AsyncioRuntime() + notification_data = loop_manager.loop.run_until_complete(live_queue.get()) + self.assertEqual(notification_data.get("id"), live_id) + self.assertEqual(notification_data.get("action"), "CREATE") diff --git a/tests/integration/blocking/test_update.py b/tests/integration/blocking/test_update.py index 6bab1471..2b3488b6 100644 --- a/tests/integration/blocking/test_update.py +++ b/tests/integration/blocking/test_update.py @@ -64,8 +64,6 @@ def test_update_person_with_tags(self): }, ) - print("outcome: ", outcome) - self.assertEqual( { "id": RecordID.parse("person:失败"), diff --git a/tests/scripts/runner.py b/tests/scripts/runner.py index aca119e9..ef4e5790 100644 --- a/tests/scripts/runner.py +++ b/tests/scripts/runner.py @@ -102,4 +102,4 @@ def run_tests(port: int, protocol: str) -> None: run_tests(port=container.port, protocol="ws") container.stop() container.remove() - port += 1 + port += 1 \ No newline at end of file diff --git a/tests/unit/test_cbor.py b/tests/unit/test_cbor.py index bc9ca4f2..45139a96 100644 --- a/tests/unit/test_cbor.py +++ b/tests/unit/test_cbor.py @@ -47,6 +47,4 @@ def test_uuid(self): uid = uuid.uuid4() encoded = encode(uid) decoded = decode(encoded) - print(encoded.hex()) - print(uid) - print(decoded) + diff --git a/tests/unit/test_clib_connection.py b/tests/unit/test_clib_connection.py index 8f5c959a..10766073 100644 --- a/tests/unit/test_clib_connection.py +++ b/tests/unit/test_clib_connection.py @@ -11,5 +11,5 @@ async def asyncSetUp(self): self.clib = CLibConnection(base_url='surrealkv://', logger=self.logger, encoder=encode, decoder=decode) await self.clib.connect() - async def test_send(self): - await self.clib.send('use', "test_ns", "test_db") + # async def test_send(self): + # await self.clib.send('use', "test_ns", "test_db") diff --git a/tests/unit/test_ws_connection.py b/tests/unit/test_ws_connection.py index 1802d8e4..d79d0d8d 100644 --- a/tests/unit/test_ws_connection.py +++ b/tests/unit/test_ws_connection.py @@ -19,8 +19,6 @@ async def test_send(self): self.ws_con.set_token(token) live_id = await self.ws_con.send("live", "users") - print("Live id: ", live_id) - live_queue = await self.ws_con.live_notifications(live_id) await self.ws_con.send("query", "CREATE users;")