Skip to content

Commit

Permalink
fix: refresh log timeout not triggering
Browse files Browse the repository at this point in the history
#1286 caused a regression where fetchFolderLogs is no longer called every 2s.
Added () and a catch so that it's called correctly. Also, refreshInterval is
a constant so shouldn't be part of the state.

Tempted to make the interval a parameter to reduce test time, but started by just
adding a test that waits to confirm the timeout starts triggering with 3.5s.

Fixes #1303.

Signed-off-by: Tim deBoer <[email protected]>
  • Loading branch information
deboer-tim committed Feb 20, 2025
1 parent 178d630 commit 865fd2f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
***********************************************************************/

import { render, screen, waitFor } from '@testing-library/svelte';
import { vi, test, expect, beforeAll } from 'vitest';
import { vi, test, expect, beforeAll, beforeEach } from 'vitest';
import DiskImageDetailsBuild from './DiskImageDetailsBuild.svelte';
import { bootcClient } from '/@/api/client';
import type { Subscriber } from '/@shared/src/messages/MessageProxy';
Expand Down Expand Up @@ -50,6 +50,10 @@ beforeAll(() => {
});
});

beforeEach(() => {
vi.clearAllMocks();
});

const mockLogs = `Build log line 1
Build log line 2
Build log line 3`;
Expand Down Expand Up @@ -81,3 +85,21 @@ test('Handles empty logs correctly', async () => {
const emptyMessage = await screen.findByText('Unable to read image-build.log file from /empty/logs');
expect(emptyMessage).toBeDefined();
});

test('Refreshes logs correctly', async () => {
vi.mocked(bootcClient.loadLogsFromFolder).mockResolvedValue(mockLogs);
vi.mocked(bootcClient.getConfigurationValue).mockResolvedValue(14);

render(DiskImageDetailsBuild, { folder: '/empty/logs' });

// verify we start refreshing logs
await vi.waitFor(
() => {
expect(bootcClient.loadLogsFromFolder).toHaveBeenCalledTimes(2);
},
{
timeout: 3500,
interval: 250,
},
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let { folder }: Props = $props();
let logsXtermDiv = $state<HTMLDivElement>();
let noLogs = $state(true);
let previousLogs = $state('');
const refreshInterval = $state(2000);
const refreshInterval = 2000;
// Terminal resize
let resizeObserver = $state<ResizeObserver>();
Expand Down Expand Up @@ -88,7 +88,7 @@ onMount(async () => {
// not possible through RPC calls (yet).
await fetchFolderLogs();
logInterval = setInterval(() => {
fetchFolderLogs;
fetchFolderLogs().catch((e: unknown) => console.error('error fetching logs', e));
}, refreshInterval);
// Resize the terminal each time we change the div size
Expand Down

0 comments on commit 865fd2f

Please sign in to comment.