Running Tests Locally
This guide walks you through setting up and running the NullOpsDevs.LibSsh test suite on your local machine.
Prerequisites
Before running tests, ensure you have the following installed:
Quick Start
1. Clone the Repository
2. Start the SSH Test Server
The test suite requires a Docker-based SSH server to be running:
Wait for the container to be healthy (usually takes 5-10 seconds):
You should see:
3. Run the Tests
From the test project directory, simply run:
The test runner will:
Load the native libssh2 library
Wait for Docker containers to be ready
Run all test categories
Display a summary of results
Test Categories
The test suite includes the following categories:
Authentication Tests
Retrieve negotiated methods
Host key retrieval
Host key hash retrieval
Password authentication
Public key authentication (with and without passphrase)
Public key from memory
SSH agent authentication
Command Execution Tests
Basic command execution
Command with exit codes
Command with stderr output
Commands with PTY allocation
Long-running commands
File Transfer Tests
SCP upload (small, medium, large files)
SCP download (small, medium, large files)
File transfer error handling
Terminal Features Tests
PTY allocation
Terminal modes configuration
Window size configuration
Error Handling Tests
Authentication failures
Connection timeouts
Invalid commands
File transfer errors
Edge Case Tests
Multiple sequential operations
Timeout handling
Large output handling
Connection with deprecated methods
Parallel sessions (15 concurrent connections)
Running Stress Tests
For performance testing with 2,000 parallel connections:
Test Server Configuration
The Docker-based SSH test server is configured with:
Port: 2222 (mapped to host)
Username:
userPassword:
12345SSH Keys: Located in
docker/test-keys/Test Files: Pre-generated in
/test-files/inside the containersmall.txt- Small text filemedium.bin- 1MB binary filelarge.dat- 10MB binary file
Server Limits
The test server is configured to handle high connection loads:
MaxStartups: 1000:30:2000
MaxSessions: 1000
File descriptors: 65536
Max processes: 32768
Troubleshooting
Docker Container Not Starting
Check Docker daemon status:
View container logs:
Rebuild the container if needed:
Connection Refused Errors
Ensure the SSH server is listening on port 2222:
If the connection fails, restart the container:
Tests Timing Out
The test runner waits up to 60 seconds for containers to be ready. If tests still time out:
Check Docker resource allocation (CPU/memory)
Verify no firewall is blocking port 2222
Manually test SSH connection:
Native Library Load Failures
If you see "Failed to load native library":
Ensure the NullOpsDevs.LibSsh package is properly restored
Check that your platform is supported (Windows x64, Linux x64/ARM64, macOS x64/ARM64)
Try cleaning and rebuilding:
The native libraries are automatically copied to the output directory (bin/Debug/net9.0/native/) during build from the NuGet package.
Port 2222 Already in Use
If port 2222 is already in use:
Cleaning Up
Stop the Test Server
Remove Test Container and Images
Full Cleanup (including volumes)
CI/CD Integration
The test suite is designed to run in CI/CD environments. See .github/workflows/ for GitHub Actions examples.
Environment Variables
CRAZY_LOAD_TEST- Set to1to enable stress testing with 2,000 parallel connections
Example GitHub Actions Workflow
Test Output
Successful test runs will display colorful output using Spectre.Console:
See Also
Performance and Reliability - Stress test results and memory profiling
Session Lifecycle - Understanding SSH session states
Error Handling - Handling SSH errors in your applications