Skip to content

Commit

Permalink
Fix integration tests (#243)
Browse files Browse the repository at this point in the history
* Fix IntegrationTests
- Add README file to explain how to run tests.
- Update docker-compose bash commands to not fail when running init containers.
- Update shell scripts with some echo commands for clarity.
  • Loading branch information
loicberthou authored Dec 12, 2023
1 parent 9fb123b commit 6bafafc
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 5 deletions.
60 changes: 60 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Testing Pulsar .NET Client

## Run All Tests (TL;DR)
```bash
cd pulsar-client-dotnet
dotnet test tests
```

## Unit Tests
You can run the unit tests without installing or running Pulsar on your machine.

### Within your IDE
You can run the unit tests within your IDE. For example, in Visual Studio, you can right-click on the `UnitTests` project and select `Run Tests`.
On JetBrains Rider, you can right-click on the `UnitTests` project and select `Run UnitTests`.

### From the command line
You can run the unit tests from the command line. From the root of the repository, run the following command:
```bash
cd pulsar-client-dotnet/tests/UnitTests
dotnet test tests/UnitTests.csproj
```

## Integration Tests

### Prerequisites
You must have a Pulsar cluster running to run the integration tests.

#### Disable the TLS tests (optional)
It is recommended to disable the TLS tests if you don't have a Pulsar cluster running with TLS enabled.

In Rider, You can disable the TLS tests by right clicking on the `IntegrationTests` project and selecting `Properties`.
Then, in the `Debug` tab, add `NOTLS` to the `Define constants` field.

Alternatively, you can simply add the following lines in `IntegrationTests.fsproj`:
```xml
<PropertyGroup>
<DefineConstants>TRACE;NOTLS</DefineConstants>
</PropertyGroup>
```

#### Using the provided Docker Compose file
You can run a Pulsar cluster locally using Docker.
You can use the provided `docker-compose.yml` file to run a Pulsar cluster locally.
From the root of the repository, run the following command:
```bash
cd pulsar-client-dotnet/tests/IntegrationTests/compose
docker-compose up -d
```
Since the docker-compose will expose the ports at the default port number, you shouldn't have to update the `pulsarAddress` in `Common.fs` to point to your Pulsar cluster.

#### Using your own Pulsar cluster (with minikube)
You can run a Pulsar cluster locally using minikube.
Make sure that you update the `pulsarAddress` in `Common.fs` to point to your Pulsar cluster.

### Running the tests
You can run the integration tests from the command line. From the root of the repository, run the following command:
```bash
cd pulsar-client-dotnet/tests/IntegrationTests
dotnet test tests/IntegrationTests.csproj
```
8 changes: 4 additions & 4 deletions tests/compose/standalone/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ services:
- ./scripts/wait-for-it.sh:/pulsar/bin/wait-for-it.sh
- ./scripts/init-standalone.sh:/pulsar/bin/init-standalone.sh
command: >
bash -c "tr -d '\r' < bin/init-standalone.sh > bin/init-standalone-fixed.sh &&
tr -d '\r' < bin/wait-for-it.sh > bin/wait-for-it-fixed.sh &&
bash -c "tr -d '\\r' < bin/init-standalone.sh > bin/init-standalone-fixed.sh &&
tr -d '\\r' < bin/wait-for-it.sh > bin/wait-for-it-fixed.sh &&
chmod u+x bin/wait-for-it-fixed.sh &&
chmod u+x bin/init-standalone-fixed.sh &&
bin/wait-for-it-fixed.sh standalone:8080 -t 120 &&
Expand Down Expand Up @@ -67,8 +67,8 @@ services:
- ./scripts/wait-for-it.sh:/pulsar/bin/wait-for-it.sh
- ./scripts/init-standalone-tls.sh:/pulsar/bin/init-standalone-tls.sh
command: >
bash -c "tr -d '\r' < bin/init-standalone-tls.sh > bin/init-standalone-tls-fixed.sh &&
tr -d '\r' < bin/wait-for-it.sh > bin/wait-for-it-fixed.sh &&
bash -c "tr -d '\\r' < bin/init-standalone-tls.sh > bin/init-standalone-tls-fixed.sh &&
tr -d '\\r' < bin/wait-for-it.sh > bin/wait-for-it-fixed.sh &&
chmod u+x bin/wait-for-it-fixed.sh &&
chmod u+x bin/init-standalone-tls-fixed.sh &&
bin/wait-for-it-fixed.sh standaloneTls:8443 -t 120 &&
Expand Down
7 changes: 7 additions & 0 deletions tests/compose/standalone/scripts/init-standalone-tls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ bin/apply-config-from-env.py conf/client.conf

sleep 5

echo "Creating 'standalone' cluster..."
bin/pulsar-admin clusters create standalone --broker-url pulsar://localhost:6650 --url http://localhost:8080

echo "Creating 'public' tenant..."
bin/pulsar-admin tenants create public

echo "Creating 'default' namespace..."
bin/pulsar-admin namespaces create public/default

echo "Init Standalone TLS completed!"
11 changes: 10 additions & 1 deletion tests/compose/standalone/scripts/init-standalone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ bin/apply-config-from-env.py conf/client.conf

sleep 5

echo "Creating namespaces..."
bin/pulsar-admin namespaces create public/retention
bin/pulsar-admin namespaces create public/deduplication

echo "Setting namespaces settings..."
bin/pulsar-admin namespaces set-retention public/retention --time 3h --size 1G
bin/pulsar-admin namespaces set-deduplication public/deduplication --enable
bin/pulsar-admin namespaces set-schema-validation-enforce --enable public/default

echo "Creating partitioned topics..."
bin/pulsar-admin topics create-partitioned-topic persistent://public/default/partitioned --partitions 3
bin/pulsar-admin topics create-partitioned-topic persistent://public/default/partitioned2 --partitions 2
bin/pulsar-admin topics create-partitioned-topic persistent://public/default/partitioned3 --partitions 3
Expand All @@ -17,4 +22,8 @@ bin/pulsar-admin topics create-partitioned-topic persistent://public/default/par
bin/pulsar-admin topics create-partitioned-topic persistent://public/default/partitioned6 --partitions 2
bin/pulsar-admin topics create-partitioned-topic persistent://public/default/partitioned-dl-test --partitions 2
bin/pulsar-admin topics create-partitioned-topic persistent://public/deduplication/partitioned --partitions 3
bin/pulsar initialize-transaction-coordinator-metadata -cs standalone:2181 -c standalone --initial-num-transaction-coordinators 2

echo "Initializing transaction coordinator metadata..."
bin/pulsar initialize-transaction-coordinator-metadata -cs standalone:2181 -c standalone --initial-num-transaction-coordinators 2

echo "Init Standalone completed!"

0 comments on commit 6bafafc

Please sign in to comment.