Skip to content

Commit a8b006e

Browse files
Adds tests (#31)
So many tests
1 parent 9ddb9c0 commit a8b006e

30 files changed

Lines changed: 832 additions & 204 deletions

.github/workflows/Test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ on:
77
branches:
88
- v2
99
jobs:
10-
unit-tests:
11-
name: Unit Tests
10+
unit-tests-php:
11+
name: Unit Tests - PHP
1212
runs-on: self-hosted
1313
steps:
1414
- uses: actions/checkout@v4

.github/workflows/build-cli.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ jobs:
4848
path: bin/dphp
4949
build-docker:
5050
runs-on: self-hosted
51+
outputs:
52+
image: ${{ steps.meta.outputs.tags }}
5153
steps:
5254
- uses: actions/checkout@v4
5355
- name: Login to Docker Hub
@@ -102,6 +104,19 @@ jobs:
102104
cache-from: type=gha,scope=image
103105
cache-to: type=gha,mode=max,scope=image
104106
platforms: linux/amd64,linux/arm64
107+
- name: Build Test Image
108+
uses: docker/build-push-action@v5
109+
with:
110+
context: ./
111+
file: Dockerfile
112+
target: test
113+
push: true
114+
pull: true
115+
tags: ghcr.io/${{ github.repository_owner }}/durable-php/runtime-tests:${{ github.sha }}
116+
labels: ${{ steps.meta.outputs.labels }}
117+
builder: ${{ steps.buildx.outputs.name }}
118+
cache-from: type=gha,scope=image
119+
platforms: linux/amd64
105120
build-osx:
106121
strategy:
107122
fail-fast: true
@@ -143,3 +158,40 @@ jobs:
143158
with:
144159
name: dphp-${{ runner.os }}-${{ matrix.platform }}
145160
path: cli/dist/dphp
161+
performance-test:
162+
name: Performance Test
163+
needs:
164+
- build-docker
165+
- build-linux
166+
runs-on: self-hosted
167+
container: ghcr.io/${{ github.repository_owner }}/durable-php/runtime-tests:${{ github.sha }}
168+
services:
169+
dphp:
170+
image: ghcr.io/${{ github.repository_owner }}/durable-php/runtime-tests:${{ github.sha }}
171+
ports:
172+
- 8080:8080
173+
volumes:
174+
- ${{ github.workspace }}:/app
175+
env:
176+
DPHP_HOST: http://dphp:8080
177+
steps:
178+
- uses: actions/checkout@v4
179+
- run: |
180+
dphp composer install
181+
- run: |
182+
echo "Running perf test"
183+
dphp exec tests/PerformanceTests/PerformanceClient.php
184+
echo "Running fan out/in test"
185+
dphp exec tests/PerformanceTests/FanOutFanInClient.php
186+
echo "Running seq test"
187+
dphp exec tests/PerformanceTests/SequenceClient.php
188+
- uses: peter-evans/find-comment@v3
189+
id: fc
190+
with:
191+
issue-number: ${{ github.event.pull_request.number }}
192+
body-includes: Performance Metrics
193+
- uses: peter-evans/create-or-update-comment@v4
194+
with:
195+
comment-id: ${{ steps.fc.outputs.comment-id }}
196+
issue-number: ${{ github.event.pull_request.number }}
197+
body-path: report.md

.github/workflows/cleanup.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Package Cleanup
2+
on:
3+
schedule:
4+
- cron: "0 0 * * *"
5+
jobs:
6+
dangling-images:
7+
name: Clean up dangling images
8+
runs-on: self-hosted
9+
steps:
10+
- uses: actions/delete-package-versions@v5
11+
with:
12+
package-name: runtime
13+
package-type: container
14+
min-versions-to-keep: 5
15+
delete-only-untagged-versions: 'true'
16+
old-test-images:
17+
name: Clean up test images
18+
runs-on: self-hosted
19+
steps:
20+
- uses: actions/delete-package-versions@v5
21+
with:
22+
package-name: 'runtime-tests'
23+
package-type: 'container'
24+
min-versions-to-keep: 10

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,16 @@ ARG VERSION=dev
103103
ENV CGO_LDFLAGS="-lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS" CGO_CFLAGS="-DFRANKENPHP_VERSION=$VERSION $PHP_CFLAGS" CGO_CPPFLAGS=$PHP_CPPFLAGS
104104
ENV GOBIN=/usr/local/bin
105105
RUN go get durable_php
106+
#RUN go test ./...
107+
106108
RUN go install -ldflags "-w -s -X 'main.version=$VERSION'"
107109

108110
FROM common AS durable-php
109111
COPY --from=builder /usr/local/bin/durable_php /usr/local/bin/dphp
110112
ENTRYPOINT ["dphp"]
111113

112114
WORKDIR /app
115+
116+
FROM durable-php AS test
117+
COPY . .
118+
CMD ["--bootstrap=tests/PerformanceTests/bootstrap.php","--port=8080"]

bin/composer.phar

2.84 MB
Binary file not shown.

cli/auth/resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func (r *Resource) isUserPermitted(perms CreatePermissions, ctx context.Context)
210210
}
211211

212212
func (r *Resource) isUserExplicitlyPermitted(perms CreatePermissions, ctx context.Context) bool {
213-
if user := ctx.Value(appcontext.CurrentUserKey).(*User); user != nil {
213+
if user, ok := ctx.Value(appcontext.CurrentUserKey).(*User); ok {
214214
if slices.Contains(perms.Users, user.UserId) {
215215
return true
216216
}

cli/lib/index.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ func CreateEntityIndex(ctx context.Context, client *typesense.Client, config *co
2020
{
2121
Name: "name", Type: "string", Facet: pointer.True(),
2222
},
23-
{
24-
Name: "id", Type: "string",
25-
},
2623
{
2724
Name: ".*", Type: "auto",
2825
},
@@ -54,9 +51,6 @@ func CreateOrchestrationIndex(ctx context.Context, client *typesense.Client, con
5451
{
5552
Name: "instance_id", Type: "string", Facet: pointer.True(),
5653
},
57-
{
58-
Name: "id", Type: "string",
59-
},
6054
{
6155
Name: "created_at", Type: "string",
6256
},
@@ -72,6 +66,9 @@ func CreateOrchestrationIndex(ctx context.Context, client *typesense.Client, con
7266
},
7367
Name: config.Stream + "_orchestrations",
7468
})
69+
if err != nil {
70+
return err
71+
}
7572

7673
return nil
7774
}

cli/lib/indexer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func IndexerListen(ctx context.Context, config *config.Config, kind glue.IdKind,
7676
BatchSize: pointer.Int(40),
7777
})
7878
if err != nil {
79-
logger.Warn("Failure uploading batch to index", zap.Error(err))
79+
logger.Warn("Failure uploading entity batch to index", zap.Error(err))
8080
continue
8181
}
8282
}
@@ -200,7 +200,7 @@ func IndexerListen(ctx context.Context, config *config.Config, kind glue.IdKind,
200200
BatchSize: pointer.Int(40),
201201
})
202202
if err != nil {
203-
logger.Warn("Failure uploading batch to index", zap.Error(err))
203+
logger.Warn("Failure uploading orchestration batch to index", zap.Error(err))
204204
continue
205205
}
206206
}

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
"license": "MIT",
2727
"name": "bottledcode/durable-php",
2828
"require": {
29-
"adhocore/cli": "^1.6.2",
29+
"adhocore/cli": "^1.7.1",
3030
"amphp/file": "^3.0.2",
3131
"amphp/http-client": "^v5.0.1",
3232
"amphp/log": "^v2.0.0",
33-
"amphp/parallel": "^2.2.8",
33+
"amphp/parallel": "^2.2.9",
3434
"crell/serde": "^1.1.0",
3535
"nesbot/carbon": ">2.0",
3636
"php": ">=8.3",
@@ -40,9 +40,9 @@
4040
"webonyx/graphql-php": "^15.11.1"
4141
},
4242
"require-dev": {
43-
"laravel/pint": "^1.14.0",
43+
"laravel/pint": "^1.15.1",
4444
"mockery/mockery": "^1.6.11",
45-
"pestphp/pest": "^2.34.5"
45+
"pestphp/pest": "^2.34.7"
4646
},
4747
"scripts": {
4848
"test": "pest"

src/DurableClient.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
use Bottledcode\DurablePhp\State\EntityState;
3030
use Bottledcode\DurablePhp\State\OrchestrationInstance;
3131
use Bottledcode\DurablePhp\State\Status;
32+
use Closure;
3233
use DateTimeImmutable;
3334
use Generator;
35+
use Override;
3436

3537
final readonly class DurableClient implements DurableClientInterface
3638
{
@@ -123,14 +125,20 @@ public function getEntitySnapshot(EntityId $entityId, string $type): ?EntityStat
123125
return $this->entityClient->getEntitySnapshot($entityId, $type);
124126
}
125127

126-
public function signal(EntityId|string $entityId, \Closure $signal): void
128+
public function signal(EntityId|string $entityId, Closure $signal): void
127129
{
128130
$this->entityClient->signal($entityId, $signal);
129131
}
130132

131-
#[\Override] public function withAuth(string $token): void
133+
#[Override]
134+
public function withAuth(string $token): void
132135
{
133136
$this->orchestrationClient->withAuth($token);
134137
$this->entityClient->withAuth($token);
135138
}
139+
140+
public function deleteEntity(EntityId $entityId): void
141+
{
142+
$this->entityClient->deleteEntity($entityId);
143+
}
136144
}

0 commit comments

Comments
 (0)