Conversation
Implements Apache Pulsar preset for Gnomock to enable integration testing with real Pulsar instances without mocks. Key features: - Official Docker image support (apachepulsar/pulsar:4.1.2) - Standalone mode for testing - Default ports: 6650 (broker), 8080 (web service) - Health checks via web service metrics endpoint - Initial state setup with topic creation and message support - Configuration options: WithVersion, WithTopics, WithMessages Addresses issue orlangure#103
Implements Apache Pulsar preset for Gnomock to enable integration testing with real Pulsar instances without mocks. - Uses official apachepulsar/pulsar:4.1.2 image - Supports standalone mode - Implements health checks via web service metrics - Supports initial topic creation and message ingestion via REST API Closes orlangure#103
There was a problem hiding this comment.
Pull request overview
This PR implements a new Apache Pulsar preset for the Gnomock testing framework, enabling integration testing with real Pulsar instances. The implementation follows established patterns from existing messaging presets (RabbitMQ, Kafka) and provides essential features for testing: topic creation, message ingestion, and health checks.
Key Changes:
- Adds Pulsar preset using official
apachepulsar/pulsar:4.1.2Docker image with configurable versions - Implements topic creation and message sending via Pulsar's admin and REST APIs
- Provides health checks using the web service metrics endpoint with named ports for broker (6650) and web service (8080)
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| preset/pulsar/preset.go | Core preset implementation with health checks, initialization, topic creation, and message sending logic |
| preset/pulsar/options.go | Configuration options for version, topics, and messages following standard Option pattern |
| preset/pulsar/preset_test.go | Comprehensive tests covering default configuration, multiple versions (3.0.0, 4.1.2), and health checks |
| .gitignore | Adds *.test pattern to exclude compiled test binaries |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| gnomock.WithInit(p.initf), | ||
| } | ||
|
|
There was a problem hiding this comment.
The WithInit option should be added conditionally based on whether there are Topics or Messages to process, similar to how RabbitMQ and Kafka presets handle this. This avoids unnecessary initialization overhead when no setup is needed. Add a conditional check before appending WithInit to opts.
| gnomock.WithInit(p.initf), | |
| } | |
| } | |
| if len(p.Messages) > 0 || len(p.Topics) > 0 { | |
| opts = append(opts, gnomock.WithInit(p.initf)) | |
| } |
| // Wait a bit for Pulsar to be fully ready after healthcheck passes | ||
| time.Sleep(2 * time.Second) |
There was a problem hiding this comment.
Using an unconditional time.Sleep in the initialization function ignores the context and can cause unnecessary delays. This is problematic because: 1) it doesn't respect context cancellation, and 2) it adds fixed delay even when Pulsar might be ready sooner. Consider implementing a polling mechanism with context-aware retries, similar to the pattern used in preset/splunk/init.go, or verify that the sleep is actually necessary by checking if topic creation fails without it.
| @@ -0,0 +1,235 @@ | |||
| // Package pulsar provides a Gnomock Preset for Apache Pulsar. | |||
There was a problem hiding this comment.
Missing README.md documentation file. Similar presets (kafka, rabbitmq) include readme.md files that provide usage examples, configuration details, and important notes for users. This documentation is important for developers who want to use this preset.
| defer resp.Body.Close() | ||
| require.Equal(t, http.StatusOK, resp.StatusCode) |
There was a problem hiding this comment.
Response body is not being closed properly in the loop. Each iteration creates a new response that shadows the previous one, preventing deferred Close() calls from executing until after the loop completes. This creates a resource leak. Move the response variable declaration inside the loop and close it immediately after checking the status code.
| defer resp.Body.Close() | |
| require.Equal(t, http.StatusOK, resp.StatusCode) | |
| require.Equal(t, http.StatusOK, resp.StatusCode) | |
| resp.Body.Close() |
Implements Apache Pulsar preset for Gnomock to enable integration testing with real Pulsar instances without mocks. This addresses issue #103.
Description
This PR adds a new Apache Pulsar preset that follows the established patterns of existing RabbitMQ and Kafka presets. The implementation uses the official Apache Pulsar Docker image and provides a minimal, straightforward setup suitable for testing and development environments.
Key Features
apachepulsar/pulsar:4.1.2(configurable viaWithVersion())pulsar.BrokerPortpulsar.WebServicePortWithTopics())WithMessages())