Skip to content

Latest commit

 

History

History
165 lines (125 loc) · 6.61 KB

TESTING.md

File metadata and controls

165 lines (125 loc) · 6.61 KB

Testing Guide

This document describes the testing strategy for tus-java-server, how to execute each testing tier, and step-by-step instructions for manual lock contention testing.


1. The Three-Tiered Testing Strategy

The repository follows a three-tiered testing hierarchy (see Architecture Guide for architectural details):

  1. Unit Tests (*Test.java): Pure offline tests using Mockito. Fast (< 2s), zero containers or network dependencies. Run with:
    mvn test -q
  2. Integration Tests (IT*): End-to-end multi-backend validation using Testcontainers (Podman or Docker). Tested across Disk, S3 (RustFS), and Azure (Azurite) in CI. Run with:
    mvn verify -q
  3. Conformity Tests (scripts/*_conformity_test.py): Socket-level Python protocol verification suites executed against running server deployments. See the Conformity Testing Guide for full instructions:
    python3 scripts/tus_conformity_test.py --url http://localhost:8080/test/api/upload
    python3 scripts/rufh_conformity_test.py --url http://localhost:8080/test/api/upload

2. Manual Testing & Contention Verification

Setup & Running the Server

Before performing the manual verification, you need to compile the library and start the Spring Boot demo server.

1. Build and install the tus-java-server library:

In the root directory of the tus-java-server project, run:

mvn clean install

2. Update the dependency version in the demo server:

Open the spring-boot-rest/pom.xml file in the sibling tus-java-server-spring-demo project and update the version of tus-java-server to the locally built SNAPSHOT version:

<dependency>
  <groupId>me.desair.tus</groupId>
  <artifactId>tus-java-server</artifactId>
  <version>2.0.0-SNAPSHOT</version>
</dependency>

3. Build and start the Spring Boot rest demo server:

Navigate to the sibling tus-java-server-spring-demo project and build/run the server:

cd ../tus-java-server-spring-demo
mvn clean package
java -jar spring-boot-rest/target/spring-boot-rest-0.0.1-SNAPSHOT.jar

Note: The demo server runs locally on port 8080 and exposes the upload endpoint at http://localhost:8080/test/api/upload.


Cleanup

The Spring Boot demo application writes upload metadata and file chunks to your system's temporary directory under a folder named tus. To clean up any files and folders created during testing, delete the temp directory:

  • On macOS/Linux:
    rm -rf $TMPDIR/tus
    (or check your system's $TMPDIR / ${java.io.tmpdir} if configured differently)

Upload Lock Contention Resolution

This guide outlines how to manually verify that the upload lock contention resolution works as expected using the Spring Boot demo server, curl, and pv (Pipe Viewer).


Prerequisites for Client

Ensure you have the following tools installed on your client testing machine:

  • curl: Standard HTTP client.
  • pv (Pipe Viewer): Throttling tool used to simulate a slow or stalled upload.
    • macOS: brew install pv
    • Debian/Ubuntu: sudo apt-get install pv

Step-by-Step Test Procedure

Step 1: Create a New Upload Resource

Initiate a new upload to the server:

curl -X POST \
  -H "Tus-Resumable: 1.0.0" \
  -H "Upload-Length: 10000000" \
  -I http://localhost:8080/test/api/upload

Look for the Location header in the response and record the upload resource URL (e.g., http://localhost:8080/test/api/upload/000003f1-a850-49de-af03-997272d834c9). We will refer to this as ${UPLOAD_URL}.

export UPLOAD_URL='http://localhost:8080/test/api/upload/0330595f-1c0d-49f5-9e78-c40b1845157d'

Step 2: Start a Throttled PATCH Request

To simulate an active, ongoing upload that is extremely slow (or stalled), run a PATCH request using /dev/zero throttled to 50 KB/s via pv:

dd if=/dev/zero bs=1024 count=10000 | pv -L 50k | curl -X PATCH -T - \
  -H "Tus-Resumable: 1.0.0" \
  -H "Upload-Offset: 0" \
  -H "Content-Type: application/offset+octet-stream" \
  ${UPLOAD_URL}

Keep this request running in your first terminal.


Step 3: Send a HEAD Request from a Separate Terminal

While the upload in Step 2 is actively running and holding the file lock, open a second terminal window and send a HEAD request to query the offset of the same upload resource:

curl -X HEAD -H "Tus-Resumable: 1.0.0" -I ${UPLOAD_URL}

Expected Results

  • First Terminal (PATCH):
    • The stalled/throttled PATCH upload should immediately abort with an I/O error or exit because the server terminated its input stream in response to the lock release request.
  • Second Terminal (HEAD):
    • The HEAD request should succeed with status 204 No Content after a short delay (the server retries up to 300 times at 200ms intervals, a 60-second retry budget, configurable via withLockWaitTimeout(Duration), while releasing the lock).
    • The response will contain the Upload-Offset header reflecting the number of bytes successfully written to disk before the stream was interrupted (e.g., Upload-Offset: 153600).
  • Subsequent Uploads:
    • You can immediately resume the upload using a new PATCH request starting from the offset returned in the HEAD response.

Automated Unit Test Coverage Verification

To locally verify unit test coverage against a target percentage (default: 93%) and report which lines/files are not covered, you can run the Maven build with the check-coverage profile.

Run with default threshold (93%)

mvn verify -Pcheck-coverage

Run with a custom threshold (e.g., 80%)

mvn verify -Pcheck-coverage -Djacoco.coverage.limit=80

This will:

  1. Run all unit/integration tests and generate the Jacoco XML coverage report.
  2. Execute the python checking script (scripts/check-coverage.py) which parses the report.
  3. Print a detailed list of uncovered (❌) and partially covered (⚠️) lines for each file.
  4. Fail the build with exit code 1 if the overall line coverage is below the threshold, or succeed if it meets or exceeds it.

Check coverage of only new/modified lines (compared to master)

You can also use this feature to verify that any new code added in your branch is fully covered compared to another branch (such as master):

mvn verify -Pcheck-coverage -Djacoco.compare.branch=master

If there are any modified or added lines in your branch (located under src/main/java) that are not covered by unit tests, the build will output a detailed report listing only those lines and fail.