pcbjam/tests/e2e/threadpool.spec.ts
Viktor Vaczi 251056e506 Clean up test infrastructure and fix test assertions
- Replace test.skip() with proper expect() assertions when app fails to load
- Remove button-finder utility (no longer needed with element registry)
- Remove kicad tests (tested separately)
- Add findByName/clickByName helpers for bitmap buttons
- Fix element lookups: use clickByName for bitmap buttons, clickTreeItem
  for treebook pages, selectComboItem for wxChoice items
- Add SetName() to shape buttons in bitmapbuttons_test.cpp
- Remove verbose logging from print and threadpool tests
- Update README to reflect current test infrastructure

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 20:18:19 +01:00

57 lines
2.4 KiB
TypeScript

import { test, expect, tryLoadApp } from './utils/fixtures';
test.describe('Thread Pool Deadlock Tests', () => {
test('Creating hardware_concurrency threads should not deadlock', async ({ page, testLogger }) => {
// This test replicates KiCad's BS::priority_thread_pool pattern:
// - Creates hardware_concurrency() threads in the frame constructor
// - If PTHREAD_POOL_SIZE < hardware_concurrency, this will deadlock because:
// 1. Threads 1-N use pre-warmed Web Workers
// 2. Thread N+1 needs new Web Worker (posts to event loop)
// 3. Main thread busy-waits for thread to start
// 4. Busy-wait blocks event loop -> Worker message never processed
// 5. DEADLOCK (timeout)
await page.goto('/standalone/threadpool/threadpool_test.html');
// If there's a deadlock, tryLoadApp will timeout waiting for canvas
const loaded = await tryLoadApp(page, 30000);
await page.screenshot({ path: 'test-results/threadpool-01-loaded.png', fullPage: true });
// Check for success marker - all threads created and joined
const success = testLogger.consoleLogs.some(log =>
log.includes('[THREADPOOL] SUCCESS')
);
expect(loaded, 'App should load without deadlock').toBe(true);
expect(success, 'All threads should complete successfully').toBe(true);
expect(testLogger.errors.filter(e => !e.includes('favicon'))).toHaveLength(0);
});
test('Thread creation logs show all threads started', async ({ page, testLogger }) => {
await page.goto('/standalone/threadpool/threadpool_test.html');
const loaded = await tryLoadApp(page, 30000);
expect(loaded, 'App should load without deadlock').toBe(true);
// Extract hardware_concurrency from logs
const hwLog = testLogger.consoleLogs.find(log =>
log.includes('[THREADPOOL] hardware_concurrency:')
);
expect(hwLog, 'Should find hardware_concurrency log').toBeDefined();
const match = hwLog!.match(/hardware_concurrency:\s*(\d+)/);
expect(match, 'Should parse hardware_concurrency value').not.toBeNull();
const expectedThreads = parseInt(match![1], 10);
// Count "Thread X started" messages
const threadStartedLogs = testLogger.consoleLogs.filter(log =>
log.includes('[THREADPOOL] Thread') && log.includes('started')
);
// All threads should have started
expect(threadStartedLogs.length).toBe(expectedThreads);
});
});