Skip to content

Commit e6c86f8

Browse files
committed
Modified test cases for actors ttl
Signed-off-by: Amulya Varote <[email protected]>
1 parent 0bcd2e8 commit e6c86f8

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

test/actor/DemoActorReminderTtlImpl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export default class DemoActorReminderTtlImpl extends AbstractActor implements D
2020
async init(): Promise<string> {
2121
await super.registerActorReminder("my-reminder-name",
2222
Temporal.Duration.from({ seconds: 2 }), //dueTime
23-
Temporal.Duration.from({ seconds: 0.5 }), //period
24-
Temporal.Duration.from({ seconds: 0.5 }), //ttl
23+
Temporal.Duration.from({ seconds: 2 }), //period
24+
Temporal.Duration.from({ seconds: 1 }), //ttl
2525
123);
2626
return "Actor Initialized";
2727
}

test/actor/DemoActorTimerTtlImpl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export default class DemoActorTimerTtlImpl extends AbstractActor implements Demo
2020
async init(): Promise<string> {
2121
await super.registerActorTimer("my-timer-name", "countBy",
2222
Temporal.Duration.from({ seconds: 2 }), //dueTime
23-
Temporal.Duration.from({ seconds: 0.5 }), //period
24-
Temporal.Duration.from({ seconds: 0.5 }), //ttl
23+
Temporal.Duration.from({ seconds: 2 }), //period
24+
Temporal.Duration.from({ seconds: 1 }), //ttl
2525
100);
2626
return "Actor Initialized";
2727
}

test/e2e/actors.http.test.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ describe('http/actors', () => {
6363
await server.actor.registerActor(DemoActorReminder2Impl);
6464
await server.actor.registerActor(DemoActorTimerImpl);
6565
await server.actor.registerActor(DemoActorActivateImpl);
66+
await server.actor.registerActor(DemoActorTimerTtlImpl);
67+
await server.actor.registerActor(DemoActorReminderTtlImpl);
6668

6769
// Start server
6870
await server.start(); // Start the general server, this can take a while
@@ -99,13 +101,15 @@ describe('http/actors', () => {
99101
it('should register actors correctly', async () => {
100102
const actors = await server.actor.getRegisteredActors();
101103

102-
expect(actors.length).toEqual(6);
104+
expect(actors.length).toEqual(8);
103105

104106
expect(actors).toContain(DemoActorCounterImpl.name);
105107
expect(actors).toContain(DemoActorSayImpl.name);
106108
expect(actors).toContain(DemoActorReminderImpl.name);
107109
expect(actors).toContain(DemoActorTimerImpl.name);
108110
expect(actors).toContain(DemoActorActivateImpl.name);
111+
expect(actors).toContain(DemoActorTimerTtlImpl.name);
112+
expect(actors).toContain(DemoActorReminderTtlImpl.name);
109113
});
110114

111115
it('should be able to invoke an actor through a text message', async () => {
@@ -186,7 +190,7 @@ describe('http/actors', () => {
186190
expect(res0).toEqual(0);
187191

188192
// Now we wait for dueTime (2s)
189-
await (new Promise(resolve => setTimeout(resolve, 500)));
193+
await (new Promise(resolve => setTimeout(resolve, 1000)));
190194

191195
// After that the timer callback will be called
192196
// In our case, the callback increments the count attribute
@@ -196,18 +200,10 @@ describe('http/actors', () => {
196200

197201
// Every 1 second the timer gets called again, so the count attribute should change
198202
// we check this twice to ensure correct calling
199-
await (new Promise(resolve => setTimeout(resolve, 500)));
203+
await (new Promise(resolve => setTimeout(resolve, 1000)));
200204
const res2 = await actor.getCounter();
201205
expect(res2).toEqual(200);
202206

203-
await (new Promise(resolve => setTimeout(resolve, 500)));
204-
try {
205-
const res3 = await actor.getCounter();
206-
} catch(e) {
207-
//@ts-ignore
208-
console.log(e.message)
209-
}
210-
// expect(res3).toEqual(300);
211207
}, 10000);
212208
});
213209

@@ -288,14 +284,11 @@ describe('http/actors', () => {
288284

289285
await actor.removeReminder();
290286

291-
await (new Promise(resolve => setTimeout(resolve, 500)));
292-
try {
293-
const res2 = await actor.getCounter();
294-
} catch(e) {
295-
//@ts-ignore
296-
console.log(e.message)
297-
}
298-
// expect(res2).toEqual(123);
287+
await (new Promise(resolve => setTimeout(resolve, 2000)));
288+
289+
// Make sure the counter didn't change
290+
const res2 = await actor.getCounter();
291+
expect(res2).toEqual(123);
299292
});
300293
});
301294
});

0 commit comments

Comments
 (0)