Skip to content

Commit 9dd64a1

Browse files
authored
feat: Add Configuration API test for subscribe all keys (#327)
* Add test for subscribe Signed-off-by: Shubham Sharma <[email protected]> * Use done() cb Signed-off-by: Shubham Sharma <[email protected]> * Fix test Signed-off-by: Shubham Sharma <[email protected]> * Close the stream Signed-off-by: Shubham Sharma <[email protected]>
1 parent a941c3d commit 9dd64a1

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

scripts/test-e2e.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14-
./test-init.sh
14+
./scripts/test-init.sh
1515

1616
# Start gRPC tests
1717
echo "Running gRPC tests"

scripts/test-init.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14-
echo "Starting Docker"
15-
sudo service docker start
16-
sleep 3
14+
if (! docker stats --no-stream ); then
15+
echo "Docker is not running, please start it first"
16+
exit 1
17+
fi
1718

1819
# Start MQTT for Binding tests
1920
# Dashboard: http://localhost:18083 (user: admin, pass: public)

test/e2e/grpc/client.test.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -367,31 +367,32 @@ describe('grpc/client', () => {
367367
// expect(conf.items.filter(i => i.key == "myconfigkey1")[0].metadata).toHaveProperty("hello");
368368
});
369369

370-
// // @todo: figure out, subscribe doesn't pass keys but doesn't listen to anything?
371-
// // https://github.com/dapr/dapr/issues/4529
372-
// it('should be able to subscribe to configuration item changes on all keys', async () => {
373-
// const m = jest.fn(async (res: SubscribeConfigurationResponse) => { });
370+
it('should be able to subscribe to configuration item changes on all keys', async () => {
371+
const m = jest.fn(async (_res: SubscribeConfigurationResponse) => { return; });
372+
373+
const stream = await client.configuration.subscribe("config-redis", m);
374374

375-
// console.log("Creating Subscription");
376-
// await client.configuration.subscribe("config-redis", m);
375+
// Update the configuration item
376+
await DockerUtils.executeDockerCommand("dapr_redis redis-cli MSET myconfigkey3 mynewvalue||2");
377377

378-
// // Change an item
379-
// await DockerUtils.executeDockerCommand("dapr_redis redis-cli MSET myconfigkey3 mynewvalue||1");
378+
expect(m.mock.calls[0][0].items.length).toEqual(1);
379+
expect(m.mock.calls[0][0].items[0].key).toEqual("myconfigkey3");
380+
expect(m.mock.calls[0][0].items[0].value).toEqual("mynewvalue");
380381

381-
// expect(m.mock.calls.length).toEqual(1);
382-
// });
382+
stream.stop();
383+
});
383384

384385
it('should be able to subscribe to configuration item changes on specific keys', async () => {
385386
const m = jest.fn(async (_res: SubscribeConfigurationResponse) => { return; });
386387

387-
const stream1 = await client.configuration.subscribeWithKeys("config-redis", ["myconfigkey1", "myconfigkey2"], m);
388+
const stream = await client.configuration.subscribeWithKeys("config-redis", ["myconfigkey1", "myconfigkey2"], m);
388389
await DockerUtils.executeDockerCommand("dapr_redis redis-cli MSET myconfigkey1 key1_mynewvalue||1");
389390

390391
expect(m.mock.calls.length).toEqual(1);
391392
expect(m.mock.calls[0][0].items[0].key).toEqual("myconfigkey1");
392393
expect(m.mock.calls[0][0].items[0].value).toEqual("key1_mynewvalue");
393394

394-
await stream1.stop();
395+
await stream.stop();
395396
});
396397

397398
it('should be able to subscribe with metadata', async () => {
@@ -410,14 +411,14 @@ describe('grpc/client', () => {
410411
it('should be able to unsubscribe', async () => {
411412
const m = jest.fn(async (_res: SubscribeConfigurationResponse) => { return; });
412413

413-
const stream1 = await client.configuration.subscribeWithMetadata("config-redis", ["myconfigkey1", "myconfigkey2"], { "hello": "world" }, m);
414+
const stream = await client.configuration.subscribeWithMetadata("config-redis", ["myconfigkey1", "myconfigkey2"], { "hello": "world" }, m);
414415
await DockerUtils.executeDockerCommand("dapr_redis redis-cli MSET myconfigkey1 key1_mynewvalue||1");
415416

416417
expect(m.mock.calls.length).toEqual(1);
417418
expect(m.mock.calls[0][0].items[0].key).toEqual("myconfigkey1");
418419
expect(m.mock.calls[0][0].items[0].value).toEqual("key1_mynewvalue");
419420

420-
await stream1.stop();
421+
stream.stop();
421422

422423
await DockerUtils.executeDockerCommand("dapr_redis redis-cli MSET myconfigkey1 key1_mynewvalue2||1");
423424

@@ -444,8 +445,8 @@ describe('grpc/client', () => {
444445
expect(m2.mock.calls[0][0].items[0].key).toEqual("myconfigkey1");
445446
expect(m2.mock.calls[0][0].items[0].value).toEqual("key1_mynewvalue");
446447

447-
await stream1.stop();
448-
await stream2.stop();
448+
stream1.stop();
449+
stream2.stop();
449450
});
450451
});
451452
});

0 commit comments

Comments
 (0)