Skip to content

Commit f6803d5

Browse files
committed
Minor doc changes
1 parent cd49eed commit f6803d5

File tree

1 file changed

+137
-14
lines changed

1 file changed

+137
-14
lines changed

CONTRIBUTING.md

Lines changed: 137 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,150 @@ pre-commit run --all-files
2525

2626
## Running tests
2727

28-
To create a test environment, do the following:
29-
```
30-
pip install -e ".[dev]"
28+
### Prerequisites
29+
30+
Before running tests, ensure you have:
31+
- **Docker installed and running** (for automatic test database management)
32+
- Test dependencies installed: `pip install -e ".[test]"` or `pip install -e ".[dev]"` for all development dependencies
33+
34+
The `docker` Python package is required for the test framework to manage Docker containers automatically.
35+
36+
### Installation
37+
38+
To create a test environment:
39+
```bash
40+
pip install -e ".[dev]" # All development dependencies (recommended)
3141
```
3242

3343
Or if you only need specific dependency groups:
34-
```
35-
pip install -e ".[test]" # Just testing dependencies
36-
pip install -e ".[docs]" # Just documentation dependencies
44+
```bash
45+
pip install -e ".[test]" # Just testing dependencies
46+
pip install -e ".[docs]" # Just documentation dependencies
47+
pip install -e ".[build]" # Just build dependencies
48+
pip install -e ".[examples]" # Just example/demo dependencies
3749
```
3850

39-
If you have Docker installed, you can run the tests as follows. Note that
40-
you should run the tests using both standard protocol and Data API (HTTP):
41-
```
51+
### Basic Testing
52+
53+
The test framework provides **automatic Docker container management**. When you run tests without setting `SINGLESTOREDB_URL`, the framework will:
54+
55+
1. Automatically start a SingleStore Docker container (`ghcr.io/singlestore-labs/singlestoredb-dev`)
56+
2. Allocate dynamic ports to avoid conflicts (MySQL, Data API, Studio)
57+
3. Wait for the container to be ready
58+
4. Run all tests against the container
59+
5. Clean up the container after tests complete
60+
61+
#### Standard MySQL Protocol Tests
62+
```bash
63+
# Run all tests (auto-starts Docker container)
4264
pytest -v singlestoredb/tests
43-
USE_DATA_API=1 -v singlestoredb/tests
65+
66+
# Run with coverage
67+
pytest -v --cov=singlestoredb --pyargs singlestoredb.tests
68+
69+
# Run single test file
70+
pytest singlestoredb/tests/test_basics.py
71+
72+
# Run without management API tests
73+
pytest -v -m 'not management' singlestoredb/tests
4474
```
4575

46-
If you need to run against a specific server version, you can specify
47-
the URL of that server:
76+
#### Data API Tests
77+
78+
The SDK supports testing via SingleStore's **Data API** (port 9000) instead of the MySQL protocol (port 3306). This mode uses a **dual-URL system**:
79+
80+
- `SINGLESTOREDB_URL`: Set to HTTP Data API endpoint (port 9000) for test operations
81+
- `SINGLESTOREDB_INIT_DB_URL`: Automatically set to MySQL endpoint (port 3306) for setup operations
82+
83+
**Why dual URLs?** Some setup operations like `SET GLOBAL` and `USE database` commands don't work over the HTTP Data API, so they're routed through the MySQL protocol automatically.
84+
85+
Enable HTTP Data API testing:
86+
```bash
87+
# Run tests via HTTP Data API
88+
USE_DATA_API=1 pytest -v singlestoredb/tests
89+
```
90+
91+
**Known Limitations in HTTP Data API Mode:**
92+
- `USE database` command is not supported (some tests will be skipped)
93+
- Setup operations requiring `SET GLOBAL` are automatically routed to MySQL protocol
94+
95+
#### Testing Against an Existing Server
96+
97+
If you have a running SingleStore instance, you can test against it by setting `SINGLESTOREDB_URL`. The Docker container will not be started.
98+
99+
```bash
100+
# Test against MySQL protocol
101+
SINGLESTOREDB_URL=user:password@host:3306 pytest -v singlestoredb/tests
102+
103+
# Test against Data API
104+
SINGLESTOREDB_INIT_DB_URL=user:password@host:3306 \
105+
SINGLESTOREDB_URL=http://user:password@host:9000 \
106+
pytest -v singlestoredb/tests
48107
```
49-
SINGLESTOREDB_URL=user:[email protected]:3306 pytest -v singlestoredb/tests
50-
SINGLESTOREDB_URL=http://user:[email protected]:8090 pytest -v singlestoredb/tests
108+
109+
### Docker Container Details
110+
111+
When the test framework starts a Docker container automatically:
112+
113+
- **Container name**: `singlestoredb-test-{worker}-{uuid}` (supports parallel test execution)
114+
- **Port mappings**:
115+
- MySQL protocol: Random available port → Container port 3306
116+
- Data API (HTTP): Random available port → Container port 9000
117+
- Studio: Random available port → Container port 8080
118+
- **License**: Uses `SINGLESTORE_LICENSE` environment variable if set, otherwise runs without license
119+
- **Cleanup**: Container is automatically removed after tests complete
120+
121+
### Environment Variables
122+
123+
The following environment variables control test behavior:
124+
125+
- **`SINGLESTOREDB_URL`**: Database connection URL. If not set, a Docker container is started automatically.
126+
- MySQL format: `user:password@host:3306`
127+
- HTTP format: `http://user:password@host:9000`
128+
129+
- **`USE_DATA_API`**: Set to `1`, `true`, or `on` to run tests via HTTP Data API instead of MySQL protocol.
130+
- Automatically sets up the dual-URL system
131+
- Example: `USE_DATA_API=1 pytest -v singlestoredb/tests`
132+
133+
- **`SINGLESTOREDB_INIT_DB_URL`**: MySQL connection URL for setup operations (auto-set in HTTP Data API mode). Used for operations that require MySQL protocol even when testing via HTTP.
134+
135+
- **`SINGLESTORE_LICENSE`**: Optional license key for Docker container. If not provided, container runs without a license.
136+
137+
- **`SINGLESTOREDB_PURE_PYTHON`**: Set to `1` to disable C acceleration and test in pure Python mode.
138+
139+
- **`SINGLESTOREDB_MANAGEMENT_TOKEN`**: Management API token for testing management features (mark tests with `@pytest.mark.management`).
140+
141+
### Testing Best Practices
142+
143+
1. **Test both protocols**: Always run tests with both MySQL protocol and HTTP Data API before submitting:
144+
```bash
145+
pytest -v singlestoredb/tests
146+
USE_DATA_API=1 pytest -v singlestoredb/tests
147+
```
148+
149+
2. **Pure Python testing**: Test without C acceleration to ensure compatibility:
150+
```bash
151+
SINGLESTOREDB_PURE_PYTHON=1 pytest -v singlestoredb/tests
152+
```
153+
154+
3. **Management API tests**: These require a management token and are marked with `@pytest.mark.management`.
155+
156+
### Examples
157+
158+
```bash
159+
# Standard workflow - test both protocols
160+
pytest -v singlestoredb/tests
161+
USE_DATA_API=1 pytest -v singlestoredb/tests
162+
163+
# Test single module with coverage
164+
pytest -v --cov=singlestoredb.connection singlestoredb/tests/test_connection.py
165+
166+
# Test UDF functionality
167+
pytest singlestoredb/tests/test_udf.py
168+
169+
# Test against specific server (skips Docker)
170+
SINGLESTOREDB_URL=admin:pass@localhost:3306 pytest -v singlestoredb/tests
171+
172+
# Debug mode with verbose output
173+
pytest -vv -s singlestoredb/tests/test_basics.py
51174
```

0 commit comments

Comments
 (0)