Skip to content

Commit 1932d48

Browse files
committed
Add tests
1 parent 5a3b0ad commit 1932d48

File tree

6 files changed

+333
-2
lines changed

6 files changed

+333
-2
lines changed

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,11 @@
1717
"require": {
1818
"predis/predis": "^1.1",
1919
"ramsey/uuid": "^3.7"
20+
},
21+
"require-dev": {
22+
"symfony/process": "^4.0"
23+
},
24+
"scripts": {
25+
"test": "php test/index.php"
2026
}
2127
}

composer.lock

Lines changed: 52 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Tests
2+
=====
3+
4+
Because `redis-counting-semaphore` is a distributed algorithm, unit tests don't mean everything.
5+
For the correctness of the algorithm, I refer to the book (https://redislabs.com/ebook/part-2-core-concepts/chapter-6-application-components-in-redis/6-3-counting-semaphores/).
6+
7+
To test the implementation, I've come up with the simulation in this folder.
8+
9+
To run the simulation, make sure you have Docker installed and run:
10+
11+
```
12+
php index.php
13+
```
14+
15+
This will:
16+
17+
* Build a docker image from the contains of `container/`
18+
* Get a redis docker image and start it
19+
* Start 100 containers based on the docker image in `container/`
20+
* These containers will all try to obtain the same counting semaphore with a limit of 10, 3 times
21+
* Check that the amount of containers in their critical section is never great than the limit of 10
22+
* Finally, after the critical section has been entered 300 times, the script will exit.

test/container/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM shippingdocker/php-composer:latest
2+
COPY . /usr/src/myapp
3+
WORKDIR /usr/src/myapp
4+
CMD composer install && php ./index.php

test/container/composer.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "code-orange/redis-counting-semaphore-test",
3+
"description": "Container to test code-orange/redis-counting-sempahore",
4+
"type": "project",
5+
"require": {
6+
"code-orange/redis-counting-semaphore": "^0.1.0",
7+
"predis/predis": "^1.1"
8+
},
9+
"license": "proprietary",
10+
"authors": [
11+
{
12+
"name": "Tim van Dalen",
13+
"email": "[email protected]"
14+
}
15+
]
16+
}

test/container/composer.lock

Lines changed: 233 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)