Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explorer: Add a separate variable for stats fetch interval #1958

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions explorer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ VITE_DUSK_TESTNET_NODE="nodes.dusk.network"
VITE_DUSK_DEVNET_NODE="devnet.nodes.dusk.network"
VITE_MARKET_DATA_REFETCH_INTERVAL=120000
VITE_REFETCH_INTERVAL=1000
VITE_STATS_REFETCH_INTERVAL=1000
VITE_TRANSACTIONS_LIST_ENTRIES=100
```

Expand Down
10 changes: 6 additions & 4 deletions explorer/src/lib/containers/__tests__/StatisticsPanel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ vi.mock("$lib/services", async (importOriginal) => {
});

describe("StatisticsPanel", () => {
const { fetchInterval, network } = get(appStore);
const { statsFetchInterval, network } = get(appStore);

afterEach(cleanup);

Expand All @@ -58,19 +58,21 @@ describe("StatisticsPanel", () => {
// snapshot with received data from APIs
expect(container.firstChild).toMatchSnapshot();

await vi.advanceTimersByTimeAsync(fetchInterval - marketDataSettleTime);
await vi.advanceTimersByTimeAsync(
statsFetchInterval - marketDataSettleTime
);

expect(duskAPI.getStats).toHaveBeenCalledTimes(2);
expect(duskAPI.getStats).toHaveBeenNthCalledWith(2, network);

await vi.advanceTimersByTimeAsync(fetchInterval);
await vi.advanceTimersByTimeAsync(statsFetchInterval);

expect(duskAPI.getStats).toHaveBeenCalledTimes(3);
expect(duskAPI.getStats).toHaveBeenNthCalledWith(3, network);

unmount();

await vi.advanceTimersByTimeAsync(fetchInterval * 10);
await vi.advanceTimersByTimeAsync(statsFetchInterval * 10);

expect(duskAPI.getStats).toHaveBeenCalledTimes(3);
expect(duskAPI.getNodeLocations).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
const nodeLocationsStore = createDataStore(duskAPI.getNodeLocations);
const pollingStatsDataStore = createPollingDataStore(
duskAPI.getStats,
$appStore.fetchInterval
$appStore.statsFetchInterval
);

onNetworkChange((network) => {
Expand Down
6 changes: 5 additions & 1 deletion explorer/src/lib/stores/__tests__/appStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,23 @@ describe("appStore", () => {
marketDataFetchInterval: Number(env.VITE_MARKET_DATA_REFETCH_INTERVAL),
network: expectedNetworks[0].value,
networks: expectedNetworks,
statsFetchInterval: Number(env.VITE_STATS_REFETCH_INTERVAL),
transactionsListEntries: Number(env.VITE_TRANSACTIONS_LIST_ENTRIES),
});
});

it("should use default values for the fetch intervals if the env vars are missing", async () => {
vi.stubEnv("VITE_REFETCH_INTERVAL", "");
vi.stubEnv("VITE_MARKET_DATA_REFETCH_INTERVAL", "");
vi.stubEnv("VITE_STATS_REFETCH_INTERVAL", "");

const { appStore } = await import("..");
const { fetchInterval, marketDataFetchInterval } = get(appStore);
const { fetchInterval, marketDataFetchInterval, statsFetchInterval } =
get(appStore);

expect(fetchInterval).toBe(1000);
expect(marketDataFetchInterval).toBe(120000);
expect(statsFetchInterval).toBe(1000);

vi.unstubAllEnvs();
});
Expand Down
2 changes: 2 additions & 0 deletions explorer/src/lib/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const initialState = {
Number(import.meta.env.VITE_MARKET_DATA_REFETCH_INTERVAL) || 120000,
network: networks[0].value,
networks,
statsFetchInterval:
Number(import.meta.env.VITE_STATS_REFETCH_INTERVAL) || 1000,
transactionsListEntries: Number(
import.meta.env.VITE_TRANSACTIONS_LIST_ENTRIES
),
Expand Down
1 change: 1 addition & 0 deletions explorer/src/lib/stores/stores.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type AppStoreContent = {
marketDataFetchInterval: number;
network: string;
networks: NetworkOption[];
statsFetchInterval: number;
transactionsListEntries: number;
};

Expand Down
2 changes: 2 additions & 0 deletions explorer/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default defineConfig(({ mode }) => {
VITE_MARKET_DATA_REFETCH_INTERVAL:
env.VITE_MARKET_DATA_REFETCH_INTERVAL,
VITE_REFETCH_INTERVAL: env.VITE_REFETCH_INTERVAL,
VITE_STATS_REFETCH_INTERVAL: env.VITE_STATS_REFETCH_INTERVAL,
VITE_TRANSACTIONS_LIST_ENTRIES: env.VITE_TRANSACTIONS_LIST_ENTRIES,
},
},
Expand All @@ -57,6 +58,7 @@ export default defineConfig(({ mode }) => {
VITE_DUSK_TESTNET_NODE: "nodes.dusk.network",
VITE_MARKET_DATA_REFETCH_INTERVAL: "120000",
VITE_REFETCH_INTERVAL: "1000",
VITE_STATS_REFETCH_INTERVAL: "1000",
VITE_TRANSACTIONS_LIST_ENTRIES: "100",
},
environment: "jsdom",
Expand Down
Loading