From 296fdc0c307f4a31d8dd0a43c14fa997977d36fc Mon Sep 17 00:00:00 2001 From: Andrea Scartabelli Date: Fri, 5 Jul 2024 14:51:16 +0200 Subject: [PATCH] explorer: Remove market poll restart after an error Resolves #1938 --- .../stores/__tests__/marketDataStore.spec.js | 117 +----------------- explorer/src/lib/stores/marketDataStore.js | 9 -- 2 files changed, 1 insertion(+), 125 deletions(-) diff --git a/explorer/src/lib/stores/__tests__/marketDataStore.spec.js b/explorer/src/lib/stores/__tests__/marketDataStore.spec.js index 9b00a95828..4c43cb208c 100644 --- a/explorer/src/lib/stores/__tests__/marketDataStore.spec.js +++ b/explorer/src/lib/stores/__tests__/marketDataStore.spec.js @@ -109,7 +109,7 @@ describe("marketDataStore", async () => { }); }); - it("should not reset its data and continue polling after an error, without resetting it as well", async () => { + it("should not reset its data and stop the polling after an error, without resetting it as well", async () => { const error = new Error("Some error message"); /** @@ -143,130 +143,15 @@ describe("marketDataStore", async () => { await vi.advanceTimersByTimeAsync(settleTime); - /** - * The store is loading because after an error the polling - * restarts immediately and we see only the last store update here. - */ expect(get(marketDataStore)).toStrictEqual({ ...storeA, error, - isLoading: true, - }); - - await vi.advanceTimersByTimeAsync(settleTime); - - expect(get(marketDataStore)).toStrictEqual({ - data: fakeMarketDataB, - error: null, isLoading: false, - lastUpdate: new Date(), }); - }); - - it("should not restart the polling if the cause of the error is a `Response` with a 429 status", async () => { - const error = new Error("Some error message"); - - error.cause = new Response("", { status: 429 }); - - /** - * This is the result for the second call as the first one - * starts with the import and isn't resolved yet - */ - vi.mocked(duskAPI.getMarketData).mockImplementationOnce(() => - rejectAfter(settleTime, error) - ); - - await vi.advanceTimersByTimeAsync(settleTime); - - const storeA = { - data: fakeMarketDataA, - error: null, - isLoading: false, - lastUpdate: new Date(), - }; - - expect(duskAPI.getMarketData).toHaveBeenCalledTimes(1); - expect(get(marketDataStore)).toStrictEqual(storeA); - - await vi.advanceTimersByTimeAsync(marketDataFetchInterval + settleTime); - - const storeB = { - ...storeA, - error, - isLoading: false, - }; - - expect(duskAPI.getMarketData).toHaveBeenCalledTimes(2); - expect(get(marketDataStore)).toStrictEqual(storeB); await vi.advanceTimersByTimeAsync(marketDataFetchInterval * 10); expect(duskAPI.getMarketData).toHaveBeenCalledTimes(2); - expect(get(marketDataStore)).toStrictEqual(storeB); - }); - - it("should restart the polling as usual if the cause of the error is a `Response` with a different status", async () => { - /** - * We make a subscription to avoid checking again the - * status of the store for every step as we already - * tested it before. - */ - const unubscribe = marketDataStore.subscribe(() => {}); - const error = new Error("Some error message"); - - error.cause = new Response("", { status: 500 }); - - /** - * These are the results for the second and third call - * as the first one starts with the import and isn't resolved yet - */ - vi.mocked(duskAPI.getMarketData) - .mockImplementationOnce(() => rejectAfter(settleTime, error)) - .mockImplementationOnce(() => resolveAfter(settleTime, fakeMarketDataB)); - - expect(duskAPI.getMarketData).toHaveBeenCalledTimes(1); - - await vi.advanceTimersByTimeAsync(settleTime + marketDataFetchInterval); - - expect(duskAPI.getMarketData).toHaveBeenCalledTimes(2); - - await vi.advanceTimersByTimeAsync(settleTime); - - expect(duskAPI.getMarketData).toHaveBeenCalledTimes(3); - - unubscribe(); - }); - - it("should restart the polling as usual if the cause of the error is anything else", async () => { - /** - * We make a subscription to avoid checking again the - * status of the store for every step as we already - * tested it before. - */ - const unubscribe = marketDataStore.subscribe(() => {}); - const error = new Error("Some error message"); - - error.cause = new Error("some other error"); - - /** - * These are the results for the second and third call - * as the first one starts with the import and isn't resolved yet - */ - vi.mocked(duskAPI.getMarketData) - .mockImplementationOnce(() => rejectAfter(settleTime, error)) - .mockImplementationOnce(() => resolveAfter(settleTime, fakeMarketDataB)); - - expect(duskAPI.getMarketData).toHaveBeenCalledTimes(1); - - await vi.advanceTimersByTimeAsync(settleTime + marketDataFetchInterval); - - expect(duskAPI.getMarketData).toHaveBeenCalledTimes(2); - - await vi.advanceTimersByTimeAsync(settleTime); - - expect(duskAPI.getMarketData).toHaveBeenCalledTimes(3); - - unubscribe(); }); describe("Stale data checks", () => { diff --git a/explorer/src/lib/stores/marketDataStore.js b/explorer/src/lib/stores/marketDataStore.js index 8fc5f177cb..a04364d379 100644 --- a/explorer/src/lib/stores/marketDataStore.js +++ b/explorer/src/lib/stores/marketDataStore.js @@ -1,5 +1,4 @@ import { derived, get } from "svelte/store"; -import { getPathIn } from "lamb"; import { createPollingDataStore } from "$lib/dusk/svelte-stores"; import { duskAPI } from "$lib/services"; @@ -23,11 +22,7 @@ const marketDataStore = derived( ($pollingDataStore, set) => { const current = get(marketDataStore); const isDataChanged = $pollingDataStore.data !== current.data; - const isErrorChanged = $pollingDataStore.error !== current.error; const hasNewData = $pollingDataStore.data && isDataChanged; - const isRecoverableError = - $pollingDataStore.error && - getPathIn($pollingDataStore, "error.cause.status") !== 429; set({ data: $pollingDataStore.data ?? current.data, @@ -39,10 +34,6 @@ const marketDataStore = derived( ? current.lastUpdate : null, }); - - if (isErrorChanged && isRecoverableError) { - pollingDataStore.start(); - } }, initialState );