|
1 | 1 | import {expect, test} from '@playwright/test'; |
| 2 | +import type {Page, Route} from '@playwright/test'; |
2 | 3 |
|
3 | 4 | import {QUERY_MODES, TRANSACTION_MODES} from '../../../../src/utils/query'; |
4 | | -import {database} from '../../../utils/constants'; |
| 5 | +import {backend, database} from '../../../utils/constants'; |
5 | 6 | import {toggleExperiment} from '../../../utils/toggleExperiment'; |
6 | 7 | import {TenantPage, VISIBILITY_TIMEOUT} from '../TenantPage'; |
7 | 8 | import {longRunningQuery} from '../constants'; |
8 | 9 |
|
9 | 10 | import {ButtonNames, QueryEditor} from './models/QueryEditor'; |
10 | 11 |
|
| 12 | +async function setupResourcePoolMock(page: Page, pools: string[] = ['default', 'olap']) { |
| 13 | + await page.route(`${backend}/viewer/json/query?*`, async (route: Route) => { |
| 14 | + const request = route.request(); |
| 15 | + const postData = request.postData(); |
| 16 | + |
| 17 | + if (postData && postData.includes('.sys/resource_pools')) { |
| 18 | + await route.fulfill({ |
| 19 | + status: 200, |
| 20 | + contentType: 'application/json', |
| 21 | + body: JSON.stringify({ |
| 22 | + version: 8, |
| 23 | + result: [ |
| 24 | + { |
| 25 | + rows: pools.map((name) => [name]), |
| 26 | + columns: [{name: 'Name', type: 'Utf8?'}], |
| 27 | + }, |
| 28 | + ], |
| 29 | + }), |
| 30 | + }); |
| 31 | + } else { |
| 32 | + await route.continue(); |
| 33 | + } |
| 34 | + }); |
| 35 | +} |
| 36 | + |
11 | 37 | test.describe('Test Query Settings', async () => { |
12 | 38 | const testQuery = 'SELECT 1, 2, 3, 4, 5;'; |
13 | 39 |
|
@@ -252,4 +278,130 @@ test.describe('Test Query Settings', async () => { |
252 | 278 | // Restore Query Streaming experiment |
253 | 279 | await toggleExperiment(page, 'on', 'Query Streaming'); |
254 | 280 | }); |
| 281 | + |
| 282 | + test('Resource pool dropdown is populated from system view', async ({page}) => { |
| 283 | + await setupResourcePoolMock(page, ['default', 'olap']); |
| 284 | + |
| 285 | + const queryEditor = new QueryEditor(page); |
| 286 | + await queryEditor.clickGearButton(); |
| 287 | + |
| 288 | + const options = await queryEditor.settingsDialog.getResourcePoolOptions(); |
| 289 | + |
| 290 | + expect(options).toContain('No pool override'); |
| 291 | + expect(options).toContain('default'); |
| 292 | + expect(options).toContain('olap'); |
| 293 | + }); |
| 294 | + |
| 295 | + test('Resource pool selection is persisted between dialog opens', async ({page}) => { |
| 296 | + await setupResourcePoolMock(page, ['default', 'olap']); |
| 297 | + |
| 298 | + const queryEditor = new QueryEditor(page); |
| 299 | + await queryEditor.clickGearButton(); |
| 300 | + |
| 301 | + await queryEditor.settingsDialog.changeResourcePool('olap'); |
| 302 | + await queryEditor.settingsDialog.clickButton(ButtonNames.Save); |
| 303 | + await expect(queryEditor.settingsDialog.isHidden()).resolves.toBe(true); |
| 304 | + |
| 305 | + await queryEditor.clickGearButton(); |
| 306 | + const value = await queryEditor.settingsDialog.getResourcePoolValue(); |
| 307 | + |
| 308 | + expect(value).toBe('olap'); |
| 309 | + }); |
| 310 | + |
| 311 | + test('Resource pool is disabled for PG query mode', async ({page}) => { |
| 312 | + await setupResourcePoolMock(page, ['default', 'olap']); |
| 313 | + |
| 314 | + const queryEditor = new QueryEditor(page); |
| 315 | + await queryEditor.clickGearButton(); |
| 316 | + |
| 317 | + await queryEditor.settingsDialog.changeQueryMode(QUERY_MODES.pg); |
| 318 | + |
| 319 | + await expect(queryEditor.settingsDialog.isResourcePoolDisabled()).resolves.toBe(true); |
| 320 | + }); |
| 321 | + |
| 322 | + test('Selected resource pool is sent in API requests and no override omits parameter', async ({ |
| 323 | + page, |
| 324 | + }) => { |
| 325 | + const capturedBodies: Array<Record<string, unknown>> = []; |
| 326 | + |
| 327 | + await page.route(`${backend}/viewer/json/query?*`, async (route: Route) => { |
| 328 | + const request = route.request(); |
| 329 | + const postData = request.postData(); |
| 330 | + |
| 331 | + if (!postData) { |
| 332 | + await route.continue(); |
| 333 | + return; |
| 334 | + } |
| 335 | + |
| 336 | + if (postData.includes('.sys/resource_pools')) { |
| 337 | + await route.fulfill({ |
| 338 | + status: 200, |
| 339 | + contentType: 'application/json', |
| 340 | + body: JSON.stringify({ |
| 341 | + version: 8, |
| 342 | + result: [ |
| 343 | + { |
| 344 | + rows: [['default'], ['olap']], |
| 345 | + columns: [{name: 'Name', type: 'Utf8?'}], |
| 346 | + }, |
| 347 | + ], |
| 348 | + }), |
| 349 | + }); |
| 350 | + return; |
| 351 | + } |
| 352 | + |
| 353 | + const body = JSON.parse(postData) as Record<string, unknown>; |
| 354 | + capturedBodies.push(body); |
| 355 | + |
| 356 | + await route.fulfill({ |
| 357 | + status: 200, |
| 358 | + contentType: 'application/json', |
| 359 | + body: JSON.stringify({ |
| 360 | + version: 8, |
| 361 | + result: [ |
| 362 | + { |
| 363 | + rows: [], |
| 364 | + columns: [], |
| 365 | + }, |
| 366 | + ], |
| 367 | + }), |
| 368 | + }); |
| 369 | + }); |
| 370 | + |
| 371 | + const queryEditor = new QueryEditor(page); |
| 372 | + |
| 373 | + // Select a concrete resource pool and run a query |
| 374 | + await queryEditor.clickGearButton(); |
| 375 | + await queryEditor.settingsDialog.changeResourcePool('olap'); |
| 376 | + await queryEditor.settingsDialog.clickButton(ButtonNames.Save); |
| 377 | + await queryEditor.setQuery('SELECT 1;'); |
| 378 | + await queryEditor.clickRunButton(); |
| 379 | + |
| 380 | + await expect(async () => { |
| 381 | + const lastBody = capturedBodies[capturedBodies.length - 1] as { |
| 382 | + query?: string; |
| 383 | + resource_pool?: string; |
| 384 | + }; |
| 385 | + |
| 386 | + expect(lastBody.query).toContain('SELECT 1;'); |
| 387 | + expect(lastBody.resource_pool).toBe('olap'); |
| 388 | + }).toPass({timeout: VISIBILITY_TIMEOUT}); |
| 389 | + |
| 390 | + // Now switch to "No pool override" and ensure resource_pool is omitted |
| 391 | + await queryEditor.clickGearButton(); |
| 392 | + await queryEditor.settingsDialog.changeResourcePool('No pool override'); |
| 393 | + await queryEditor.settingsDialog.clickButton(ButtonNames.Save); |
| 394 | + await queryEditor.setQuery('SELECT 2;'); |
| 395 | + await queryEditor.clickRunButton(); |
| 396 | + |
| 397 | + await expect(async () => { |
| 398 | + const lastBody = capturedBodies[capturedBodies.length - 1] as { |
| 399 | + query?: string; |
| 400 | + resource_pool?: string; |
| 401 | + }; |
| 402 | + |
| 403 | + expect(lastBody.query).toContain('SELECT 2;'); |
| 404 | + expect(lastBody.resource_pool).toBeUndefined(); |
| 405 | + }).toPass({timeout: VISIBILITY_TIMEOUT}); |
| 406 | + }); |
255 | 407 | }); |
0 commit comments