Skip to content

Improve and fix github actions and workflow #123

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

Merged
merged 15 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/cross_build.yml
Original file line number Diff line number Diff line change
@@ -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 }}
44 changes: 25 additions & 19 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
name: unit-tests

on:
push:
branches:
- main
pull_request:
# push:
branches:
- "*"

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



7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.PHONY: test test_versions

test:
python -m unittest discover -s tests

test_versions:
python tests/scripts/runner.py
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions surrealdb/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions tests/integration/async/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


1 change: 0 additions & 1 deletion tests/integration/async/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion tests/integration/blocking/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 8 additions & 9 deletions tests/integration/blocking/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


2 changes: 0 additions & 2 deletions tests/integration/blocking/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ def test_update_person_with_tags(self):
},
)

print("outcome: ", outcome)

self.assertEqual(
{
"id": RecordID.parse("person:失败"),
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 1 addition & 3 deletions tests/unit/test_cbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,4 @@ def test_uuid(self):
uid = uuid.uuid4()
encoded = encode(uid)
decoded = decode(encoded)
print(encoded.hex())
print(uid)
print(decoded)

4 changes: 2 additions & 2 deletions tests/unit/test_clib_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 0 additions & 2 deletions tests/unit/test_ws_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;")
Expand Down
Loading