Skip to content

Commit f503465

Browse files
Merge pull request #209 from shubham1172/shubham1172/fix-e2e-tests
Fix actors e2e test
2 parents e56f31d + 1640cf6 commit f503465

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

test/actor/DemoActorReminderInterface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ export default interface DemoActorReminderInterface {
1515
init(): Promise<string>;
1616
count(): Promise<void>;
1717
getCounter(): Promise<number>;
18+
removeReminder(): Promise<void>;
19+
receiveReminder(data: string): Promise<void>;
1820
}

test/actor/DemoActorSayInterface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ limitations under the License.
1414
export default interface DemoActorSayInterface {
1515
sayString(msg: string): string;
1616
sayObject(msg: object): object;
17+
sayMulti(a: number, b: string, c: object, d: number[]): object;
1718
}

test/actor/DemoActorTimerInterface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ export default interface DemoActorTimerInterface {
1616
getCounter(): Promise<number>;
1717
count(): Promise<void>;
1818
countBy(amount: string): Promise<void>;
19+
removeTimer(): Promise<void>;
1920
}

test/e2e/actors.http.test.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,25 @@ limitations under the License.
1313

1414
import { CommunicationProtocolEnum, DaprClient, DaprServer } from '../../src';
1515

16+
import * as NodeJSUtil from '../../src/utils/NodeJS.util';
17+
import ActorId from '../../src/actors/ActorId';
18+
import ActorProxyBuilder from '../../src/actors/client/ActorProxyBuilder';
1619
import DemoActorActivateImpl from '../actor/DemoActorActivateImpl';
1720
import DemoActorCounterImpl from '../actor/DemoActorCounterImpl';
21+
import DemoActorCounterInterface from '../actor/DemoActorCounterInterface';
1822
import DemoActorReminderImpl from '../actor/DemoActorReminderImpl';
1923
import DemoActorReminder2Impl from '../actor/DemoActorReminder2Impl';
24+
import DemoActorReminderInterface from '../actor/DemoActorReminderInterface';
2025
import DemoActorSayImpl from '../actor/DemoActorSayImpl';
26+
import DemoActorSayInterface from '../actor/DemoActorSayInterface';
2127
import DemoActorTimerImpl from '../actor/DemoActorTimerImpl';
22-
import ActorId from '../../src/actors/ActorId';
23-
import ActorProxyBuilder from '../../src/actors/client/ActorProxyBuilder';
24-
import * as NodeJSUtil from '../../src/utils/NodeJS.util';
28+
import DemoActorTimerInterface from '../actor/DemoActorTimerInterface';
2529

2630
const serverHost = "127.0.0.1";
2731
const serverPort = "50001";
2832
const sidecarHost = "127.0.0.1";
2933
const sidecarPort = "50000";
34+
const serverStartWaitTimeMs = 5 * 1000;
3035

3136
describe('http/actors', () => {
3237
let server: DaprServer;
@@ -59,6 +64,10 @@ describe('http/actors', () => {
5964

6065
// Start server
6166
await server.start(); // Start the general server, this can take a while
67+
68+
// Wait for actor placement tables to fully start up
69+
// TODO: Remove this once healthz is fixed (https://github.com/dapr/dapr/issues/3451)
70+
await NodeJSUtil.sleep(serverStartWaitTimeMs);
6271
}, 30 * 1000);
6372

6473
afterAll(async () => {
@@ -68,13 +77,13 @@ describe('http/actors', () => {
6877

6978
describe('actorProxy', () => {
7079
it('should be able to create an actor object through the proxy', async () => {
71-
const builder = new ActorProxyBuilder<DemoActorCounterImpl>(DemoActorCounterImpl, client);
80+
const builder = new ActorProxyBuilder<DemoActorCounterInterface>(DemoActorCounterImpl, client);
7281
const actor = builder.build(ActorId.createRandomId());
7382

7483
const c1 = await actor.getCounter();
7584
expect(c1).toEqual(0);
7685

77-
await actor.countBy(1);
86+
await actor.countBy(1, 1);
7887
const c2 = await actor.getCounter();
7988
expect(c2).toEqual(1);
8089

@@ -98,36 +107,36 @@ describe('http/actors', () => {
98107
});
99108

100109
it('should be able to invoke an actor through a text message', async () => {
101-
const builder = new ActorProxyBuilder<DemoActorSayImpl>(DemoActorSayImpl, client);
110+
const builder = new ActorProxyBuilder<DemoActorSayInterface>(DemoActorSayImpl, client);
102111
const actor = builder.build(ActorId.createRandomId());
103112
const res = await actor.sayString("Hello World");
104113
expect(res).toEqual(`Actor said: "Hello World"`)
105114
});
106115

107116
it('should be able to invoke an actor through an object message', async () => {
108-
const builder = new ActorProxyBuilder<DemoActorSayImpl>(DemoActorSayImpl, client);
117+
const builder = new ActorProxyBuilder<DemoActorSayInterface>(DemoActorSayImpl, client);
109118
const actor = builder.build(ActorId.createRandomId());
110119
const res = await actor.sayObject({ hello: "world" });
111120
expect(JSON.stringify(res)).toEqual(`{"said":{"hello":"world"}}`)
112121
});
113122

114123
it('should be able to invoke an actor through multiple parameters', async () => {
115-
const builder = new ActorProxyBuilder<DemoActorSayImpl>(DemoActorSayImpl, client);
124+
const builder = new ActorProxyBuilder<DemoActorSayInterface>(DemoActorSayImpl, client);
116125
const actor = builder.build(ActorId.createRandomId());
117126
const res = await actor.sayMulti(123, "123", { hello: "world 123" }, [1, 2, 3]);
118127
expect(JSON.stringify(res)).toEqual(`{"a":{"value":123,"type":"number"},"b":{"value":"123","type":"string"},"c":{"value":{"hello":"world 123"},"type":"object"},"d":{"value":[1,2,3],"type":"object"}}`)
119128
});
120129

121130
it('should be able to invoke an actor through the client which abstracts the actor proxy builder for people unaware of patterns', async () => {
122-
const actor = client.actor.create<DemoActorSayImpl>(DemoActorSayImpl);
131+
const actor = client.actor.create<DemoActorSayInterface>(DemoActorSayImpl);
123132
const res = await actor.sayMulti(123, "123", { hello: "world 123" }, [1, 2, 3]);
124133
expect(JSON.stringify(res)).toEqual(`{"a":{"value":123,"type":"number"},"b":{"value":"123","type":"string"},"c":{"value":{"hello":"world 123"},"type":"object"},"d":{"value":[1,2,3],"type":"object"}}`)
125134
});
126135
});
127136

128137
describe('timers', () => {
129138
it('should fire a timer correctly (expected execution time > 5s)', async () => {
130-
const builder = new ActorProxyBuilder<DemoActorTimerImpl>(DemoActorTimerImpl, client);
139+
const builder = new ActorProxyBuilder<DemoActorTimerInterface>(DemoActorTimerImpl, client);
131140
const actor = builder.build(ActorId.createRandomId());
132141

133142
// Activate our actor
@@ -166,7 +175,7 @@ describe('http/actors', () => {
166175

167176
describe('reminders', () => {
168177
it('should be able to unregister a reminder', async () => {
169-
const builder = new ActorProxyBuilder<DemoActorReminderImpl>(DemoActorReminderImpl, client);
178+
const builder = new ActorProxyBuilder<DemoActorReminderInterface>(DemoActorReminderImpl, client);
170179
const actor = builder.build(ActorId.createRandomId());
171180

172181
// Activate our actor
@@ -195,7 +204,7 @@ describe('http/actors', () => {
195204
});
196205

197206
it('should fire a reminder but with a warning if it\'s not implemented correctly', async () => {
198-
const builder = new ActorProxyBuilder<DemoActorReminder2Impl>(DemoActorReminder2Impl, client);
207+
const builder = new ActorProxyBuilder<DemoActorReminderInterface>(DemoActorReminder2Impl, client);
199208
const actorId = ActorId.createRandomId();
200209
const actor = builder.build(actorId);
201210

0 commit comments

Comments
 (0)