tests/

directory
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2025 License: MIT

README ΒΆ

ChronoQueue Test Suite

Comprehensive integration and end-to-end tests for the ChronoQueue message queue system.


πŸ“ Directory Structure

tests/
β”œβ”€β”€ README.md                          # This file
β”œβ”€β”€ TESTING_GUIDE.md                   # Comprehensive testing guide
β”œβ”€β”€ TEST_IMPLEMENTATION_SUMMARY.md     # Implementation summary
β”œβ”€β”€ DELIVERABLES.md                    # Project deliverables
β”œβ”€β”€ TESTING_ENHANCEMENT_SUMMARY.md     # Testing enhancements
β”‚
β”œβ”€β”€ fixtures/                          # Test data
β”‚   β”œβ”€β”€ queues.json                   # Queue configurations
β”‚   β”œβ”€β”€ messages.json                 # Message templates
β”‚   β”œβ”€β”€ schedules.json                # Schedule configurations
β”‚   └── schemas/                      # JSON schemas
β”‚       β”œβ”€β”€ order_schema.json
β”‚       β”œβ”€β”€ event_schema.json
β”‚       └── notification_schema.json
β”‚
β”œβ”€β”€ helpers/                           # Test utilities
β”‚   β”œβ”€β”€ testcontainer.go              # Container setup
β”‚   β”œβ”€β”€ fixtures.go                   # Fixture loaders
β”‚   └── assertions.go                 # Custom assertions
β”‚
β”œβ”€β”€ integration/                       # Integration tests
β”‚   β”œβ”€β”€ queue_operations_test.go      # Queue CRUD
β”‚   β”œβ”€β”€ message_lifecycle_test.go     # Message operations
β”‚   β”œβ”€β”€ priority_queue_test.go        # Priority ordering
β”‚   β”œβ”€β”€ retry_dlq_test.go             # Retry and DLQ
β”‚   β”œβ”€β”€ scheduling_test.go            # Cron & calendar
β”‚   └── schema_registry_test.go       # Schema validation
β”‚
└── e2e/                               # End-to-end tests
    └── workflows_test.go              # Complete workflows

πŸš€ Quick Start

Prerequisites
  1. Docker must be running (for Testcontainers)
  2. Go 1.25+ installed
  3. ChronoQueue dependencies installed: go mod download
Run All Tests
# From project root
go test -v ./tests/...
Run Specific Test Suites
# Integration tests only
go test -v ./tests/integration/...

# E2E tests only
go test -v ./tests/e2e/...

# Specific test file
go test -v ./tests/integration/message_lifecycle_test.go

# Specific test function
go test -v ./tests/integration/ -run TestMessageLifecycle_PostSimpleMessage
Run with Options
# Skip long-running tests
go test -v -short ./tests/...

# Run with timeout
go test -v -timeout 30m ./tests/...

# Run in parallel
go test -v -parallel 4 ./tests/integration/...

# Generate coverage
go test -v -coverprofile=coverage.out ./tests/...
go tool cover -html=coverage.out

πŸ“Š Test Coverage

Test Suite Tests Features Covered
Queue Operations 5+ Queue CRUD, listing, state management
Message Lifecycle 10+ Post, get, acknowledge, lease, heartbeat, peek
Priority Queues 5+ Priority ordering, FIFO within priority
Retry & DLQ 8+ Exponential backoff, DLQ operations, requeue
Scheduling 8+ Cron expressions, calendar rules, management
Schema Registry 9+ Register, validate, version, delete
E2E Workflows 3+ Complete real-world scenarios

Total: 50+ comprehensive test cases


πŸ§ͺ Test Categories

Integration Tests (./integration/)

Test individual features with real Redis and ChronoQueue containers:

  • βœ… Queue Management: Create, delete, list queues
  • βœ… Message Operations: Post, get, acknowledge, renew lease
  • βœ… Priority Handling: Priority-based message ordering
  • βœ… Retry System: Exponential backoff, max retries
  • βœ… Dead Letter Queue: Auto-creation, requeue, purge
  • βœ… Scheduling: Cron and calendar-based scheduling
  • βœ… Schema Registry: JSON Schema validation
End-to-End Tests (./e2e/)

Test complete workflows combining multiple features:

  • βœ… Complete Message Workflow: Post β†’ Consume β†’ Ack β†’ DLQ β†’ Requeue
  • βœ… High-Priority Alert System: Priority-based processing
  • βœ… Multi-Tenant Isolation: Complete isolation between tenants

πŸ› οΈ Test Utilities

Fixtures (./fixtures/)

Pre-defined test data for consistent testing:

  • Queues: 5 configurations (simple, exclusive, priority, schema-enforced, no-DLQ)
  • Messages: 10 templates (various content types, priorities)
  • Schedules: 10 configurations (cron and calendar-based)
  • Schemas: 3 JSON schemas (order, event, notification)
Helpers (./helpers/)

Utility functions for common test operations:

Container Management:

  • SetupTestEnvironment() - Creates Redis + ChronoQueue containers
  • NewGRPCClient() - gRPC client connection
  • Cleanup() - Resource teardown

Fixture Loading:

  • LoadFixture() - Load JSON fixtures
  • LoadMessageFixture() - Load message templates
  • LoadJSONSchema() - Load schema files

Assertions:

  • AssertQueueExists() - Verify queue presence
  • AssertMessagePriority() - Validate priority ordering
  • AssertLeaseActive() - Check lease state
  • AssertErrorContains() - Validate error messages

πŸ“– Documentation


🎯 Example Test

func TestMessageLifecycle_PostSimpleMessage(t *testing.T) {
    t.Parallel()

    // Arrange
    ctx := context.Background()
    env := helpers.SetupTestEnvironment(t)
    conn := env.NewGRPCClient(t)
    client := queueservice_pb.NewQueueServiceClient(conn)

    queueName := helpers.GenerateUniqueQueueName(t, "test-queue")

    // Create queue
    _, err := client.CreateQueue(ctx, &queueservice_pb.CreateQueueRequest{
        Name: queueName,
        Metadata: &queue_pb.QueueMetadata{
            Type: queue_pb.QueueType_SIMPLE,
        },
    })
    require.NoError(t, err)

    // Load message from fixture
    msgFixture := helpers.LoadMessageFixture(t, "low_priority_log")

    // Act
    response, err := client.PostMessage(ctx, &queueservice_pb.PostMessageRequest{
        QueueName: queueName,
        Message:   createMessageFromFixture(t, msgFixture),
    })

    // Assert
    require.NoError(t, err)
    assert.True(t, response.Success)
}

πŸ” Troubleshooting

Docker Issues
# Verify Docker is running
docker info

# Clean up Docker resources
docker system prune -a
Test Failures
# Run with verbose output
go test -v ./tests/integration/... 2>&1 | tee test-output.log

# Run single test for debugging
go test -v ./tests/integration/ -run TestSpecificTest

# Check container logs (if test fails)
docker logs <container-id>
Timing Issues

Some tests are timing-dependent. If they fail intermittently:

# Skip timing-dependent tests
go test -v -short ./tests/...

# Increase timeouts
go test -v -timeout 60m ./tests/...

🀝 Contributing

When adding new tests:

  1. Follow existing patterns: Use Arrange-Act-Assert structure
  2. Use fixtures: Load test data from fixtures/ directory
  3. Add assertions: Use custom assertions from helpers/assertions.go
  4. Document: Add test scenario comments
  5. Parallel where safe: Use t.Parallel() for independent tests
  6. Clean up: Use t.Cleanup() for resource teardown

πŸ“ Test Naming Convention

Test<Feature>_<Scenario>_<ExpectedBehavior>

Examples:

  • TestQueueOperations_CreateSimpleQueue_Success
  • TestMessageLifecycle_GetMessage_ReturnsHighestPriority
  • TestDLQ_ExhaustedRetries_MovesToDLQ

βœ… Success Criteria

All tests should:

  • βœ… Run in isolation (no shared state)
  • βœ… Clean up resources automatically
  • βœ… Produce consistent results
  • βœ… Execute in reasonable time
  • βœ… Provide clear failure messages

πŸ“ž Support

For issues or questions:

  1. Check TESTING_GUIDE.md for detailed documentation
  2. Review TEST_IMPLEMENTATION_SUMMARY.md for implementation details
  3. Check existing test examples in integration/ and e2e/ directories

Directories ΒΆ

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL