gabotorresruiz commented on code in PR #45957:
URL: https://github.com/apache/superset/pull/45957#discussion_r4482411611
##########
superset-embedded-sdk/src/index.test.ts:
##########
@@ -537,4 +538,67 @@ describe("embedDashboard", () => {
expect(mountPoint.querySelector("iframe")).toBeNull();
expect(ports[0].close).toHaveBeenCalled();
});
+
+ it("a refresh whose fetch fails is retried after the retry delay", async ()
=> {
+ vi.useFakeTimers();
+ const mockFetchGuestToken = vi
+ .fn()
+ .mockResolvedValueOnce(fakeToken())
+ .mockRejectedValueOnce(new Error("token expired"))
+ .mockImplementationOnce(() => Promise.resolve(fakeToken()));
+ const embedding = embedDashboard({
+ id: "test-id",
+ supersetDomain: "https://superset.example.com",
+ mountPoint,
+ fetchGuestToken: mockFetchGuestToken,
+ });
+ await vi.advanceTimersByTimeAsync(0);
+ const dashboard = await embedding;
+ expect(mockFetchGuestToken).toHaveBeenCalledTimes(1);
+
+ await vi.advanceTimersByTimeAsync(300_000);
+ expect(mockFetchGuestToken).toHaveBeenCalledTimes(2);
+ expect(mockSwitchboard.emit).toHaveBeenCalledTimes(1);
+
+ await vi.advanceTimersByTimeAsync(DEFAULT_TOKEN_REFRESH_RETRY_MS);
+ expect(mockFetchGuestToken).toHaveBeenCalledTimes(3);
+ expect(mockSwitchboard.emit).toHaveBeenCalledTimes(2);
+
+ dashboard.unmount();
+ vi.useRealTimers();
+ });
+
+ it("handles unmount during token refresh", async () => {
+ const mockFetch = vi.fn().mockResolvedValue("token-1");
+
+ const result = await embedDashboard({
+ id: "test-dashboard",
+ supersetDomain: "http://localhost:8200",
+ mountPoint,
+ fetchGuestToken: mockFetch,
+ });
+
+ result.unmount();
+
+ expect(mountPoint.querySelector("iframe")).toBeNull();
+ expect(ports[0].close).toHaveBeenCalled();
+ });
Review Comment:
Added in `da47442a`, and it fails with the `unmounted` guards removed.
Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]