Skip to content

Commit db6eb8f

Browse files
committed
[IP-146] NH partitions - RFC 72 (step 3)
1 parent d1af66f commit db6eb8f

File tree

3 files changed

+73
-21
lines changed

3 files changed

+73
-21
lines changed

HandleNHCreateOrUpdateInstallationCallOrchestrator/__tests__/handler.test.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ describe("HandleNHCreateOrUpdateInstallationCallOrchestrator", () => {
125125
);
126126
});
127127

128-
it("should call CreateOrUpdate activity with legacy parameters if user is a test user", async () => {
128+
it("should call CreateOrUpdate activity with new NH parameters if user is a test user", async () => {
129129
const orchestratorHandler = getHandler({
130130
createOrUpdateActivity: mockCreateOrUpdateActivity,
131131
isUserInActiveTestSubsetActivity: mockIsUserATestUserActivityTrue,
@@ -146,11 +146,17 @@ describe("HandleNHCreateOrUpdateInstallationCallOrchestrator", () => {
146146
platform: aCreateOrUpdateInstallationMessage.platform,
147147
tags: aCreateOrUpdateInstallationMessage.tags,
148148
pushChannel: aCreateOrUpdateInstallationMessage.pushChannel,
149-
notificationHubConfig: legacyNotificationHubConfig
149+
notificationHubConfig: newNotificationHubConfig
150150
})
151151
);
152152

153-
expect(mockDeleteInstallationActivitySuccess).not.toHaveBeenCalled();
153+
expect(mockDeleteInstallationActivitySuccess).toBeCalledWith(
154+
expect.any(Object),
155+
expect.objectContaining({
156+
installationId: aCreateOrUpdateInstallationMessage.installationId,
157+
notificationHubConfig: legacyNotificationHubConfig
158+
})
159+
);
154160
}
155161
);
156162
});
@@ -195,16 +201,16 @@ describe("HandleNHCreateOrUpdateInstallationCallOrchestrator", () => {
195201
};
196202
mockGetInput.mockImplementationOnce(() => input);
197203

198-
const orchestratorHandler = getHandler({
199-
createOrUpdateActivity: mockCreateOrUpdateActivity,
200-
isUserInActiveTestSubsetActivity: mockIsUserATestUserActivityFalse,
201-
legacyNotificationHubConfig: legacyNotificationHubConfig,
202-
notificationHubConfigPartitionChooser: _ => newNotificationHubConfig,
203-
deleteInstallationActivity: mockDeleteInstallationActivitySuccess
204-
})(contextMockWithDf);
205-
206-
expect.assertions(2);
207204
try {
205+
const orchestratorHandler = getHandler({
206+
createOrUpdateActivity: mockCreateOrUpdateActivity,
207+
isUserInActiveTestSubsetActivity: mockIsUserATestUserActivityFalse,
208+
legacyNotificationHubConfig: legacyNotificationHubConfig,
209+
notificationHubConfigPartitionChooser: _ => newNotificationHubConfig,
210+
deleteInstallationActivity: mockDeleteInstallationActivitySuccess
211+
})(contextMockWithDf);
212+
213+
expect.assertions(2);
208214
consumeGenerator(orchestratorHandler);
209215
} catch (err) {
210216
expect(OrchestratorInvalidInputFailure.is(err)).toBe(true);

HandleNHCreateOrUpdateInstallationCallOrchestrator/handler.ts

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars */
22
import { Task } from "durable-functions/lib/src/classes";
33
import * as t from "io-ts";
4+
import { toString } from "fp-ts/lib/function";
45

56
import * as o from "../utils/durable/orchestrators";
7+
import { failureUnhandled } from "../utils/durable/orchestrators";
68

79
import {
810
getNotificationHubPartitionConfig,
@@ -70,14 +72,58 @@ export const getHandler = ({
7072

7173
if (isUserATestUser.value) {
7274
logger.info(`TEST_USER:${installationId}`);
73-
}
7475

75-
yield* createOrUpdateActivity(context, {
76-
installationId,
77-
notificationHubConfig: legacyNotificationHubConfig,
78-
platform,
79-
pushChannel,
80-
tags
81-
});
76+
const notificationHubConfigPartition = notificationHubConfigPartitionChooser(
77+
installationId
78+
);
79+
80+
try {
81+
yield* createOrUpdateActivity(context, {
82+
installationId,
83+
notificationHubConfig: notificationHubConfigPartition,
84+
platform,
85+
pushChannel,
86+
tags
87+
});
88+
89+
// Always delete installation from legacy Notification Hub
90+
yield* deleteInstallationActivity(context, {
91+
installationId,
92+
notificationHubConfig: legacyNotificationHubConfig
93+
});
94+
} catch (err) {
95+
// ^In case of exception, delete from partition and restore into legacy NH
96+
97+
logger.error(
98+
failureUnhandled(
99+
`ERROR|TEST_USER ${installationId}: ${toString(err)}`
100+
)
101+
);
102+
103+
yield* createOrUpdateActivity(context, {
104+
installationId,
105+
notificationHubConfig: legacyNotificationHubConfig,
106+
platform,
107+
pushChannel,
108+
tags
109+
});
110+
111+
yield* deleteInstallationActivity(context, {
112+
installationId,
113+
notificationHubConfig: notificationHubConfigPartition
114+
});
115+
116+
throw err;
117+
}
118+
} else {
119+
// Call legacy Notification Hub otherwise
120+
yield* createOrUpdateActivity(context, {
121+
installationId,
122+
notificationHubConfig: legacyNotificationHubConfig,
123+
platform,
124+
pushChannel,
125+
tags
126+
});
127+
}
82128
}
83129
);

HandleNHDeleteInstallationCallOrchestrator/__tests__/handler.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ describe("HandleNHDeleteInstallationCallOrchestrator", () => {
129129
deleteInstallationActivity: mockDeleteInstallationActivitySuccess,
130130
legacyNotificationHubConfig: legacyNotificationHubConfig,
131131
notificationHubConfigPartitionChooser: _ => newNotificationHubConfig
132-
})(contextMockWithDf as any);
132+
})(contextMockWithDf);
133133

134134
expect.assertions(2);
135135
try {

0 commit comments

Comments
 (0)