From 71cb3b0263402f790ef83c57ced1c02bee1c0a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Sadzi=C5=84ski?= Date: Mon, 23 Dec 2024 16:26:01 +0100 Subject: [PATCH 1/2] Fixing BundleActions test --- app/client/components/ColumnTransform.ts | 3 +- test/nbrowser/BundleActions.ts | 47 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/app/client/components/ColumnTransform.ts b/app/client/components/ColumnTransform.ts index 3e2881a717..710b12c5bd 100644 --- a/app/client/components/ColumnTransform.ts +++ b/app/client/components/ColumnTransform.ts @@ -234,9 +234,10 @@ export class ColumnTransform extends Disposable { } finally { // Wait until the change completed to set column back, to avoid value flickering. field.colRef(origRef); - void tableData.sendTableAction(['RemoveColumn', transformColId]); + const cleanupProm = tableData.sendTableAction(['RemoveColumn', transformColId]); this.cleanup(); this.dispose(); + await cleanupProm; } } diff --git a/test/nbrowser/BundleActions.ts b/test/nbrowser/BundleActions.ts index 31b79ffe2d..3504cac32f 100644 --- a/test/nbrowser/BundleActions.ts +++ b/test/nbrowser/BundleActions.ts @@ -7,6 +7,10 @@ import {assert, driver, Key} from 'mocha-webdriver'; import * as gu from 'test/nbrowser/gristUtils'; import {setupTestSuite} from 'test/nbrowser/testUtils'; +import {server} from "test/nbrowser/testUtils"; +import {SQLiteDB} from 'app/server/lib/SQLiteDB'; +import fs from 'fs'; + describe('BundleActions', function() { this.timeout(30000); @@ -23,6 +27,49 @@ describe('BundleActions', function() { await gu.waitForServer(); }); + it.skip('bug: bundle is properly finished', async function() { + // There was a bug in the finalization of the bundle. There was previously a race condition + // as the finalizer was sending the `RemoveAction(column)` without waiting for the result. + // So sometimes column was added before removing the transform column. This was causing + // undo to fail (known bug in grist, adding and removing columns in two tabs and then undoing + // in one tab doesn't work, as `AddColumn` action is not idempotent, undoing and redoing can + // result with different PK). + + // I don't have a good way to reproduce it. It can be done by brute force (a while loop) + // over the next test (on my machine it fails after 3 seconds). So this test is skipped and + // just a documentation of the bug for later use. + + // eslint-disable-next-line no-constant-condition + while (true) { + const rollback = await gu.begin(); + // Start a transform. + await gu.getCell({col: 'Name', rowNum: 1}).click(); + // This does not include a click on the "Apply" button. + await gu.setType(/Reference/); + assert.equal(await gu.getCell({col: 'Name', rowNum: 1}).matches('.transform_field'), true); + + // Add a column while inside the transform. + await driver.find('body').sendKeys(Key.chord(Key.ALT, Key.SHIFT, '=')); + await gu.waitForServer(); + const file = fs.readdirSync(server.testDocDir)[0]; + const fullPath = server.testDocDir + '/' + file; + // This is sqlite file, open it and read the last id in the _grist_Tables_column. + const db = await SQLiteDB.openDBRaw(fullPath); + const rows = await db.get("SELECT id FROM _grist_Tables_column ORDER BY id DESC LIMIT 1"); + await db.close(); + const lastId = rows?.id as number; + + await gu.sendKeys(Key.ESCAPE); + + // if the id == 11 break; + if (lastId != 9) { + throw new Error("The RemoveColumn in the ColumnTransform._doFinalize was processed before adding the column"); + // So in the test below, the redo used to fail. + } + await rollback(); + } + }); + it('should complete transform if column is added during it', async function() { // Start a transform. await gu.getCell({col: 'Name', rowNum: 1}).click(); From ecc763f9c43295500be23701c068216d8e1099fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Sadzi=C5=84ski?= Date: Mon, 23 Dec 2024 18:18:51 +0100 Subject: [PATCH 2/2] Fixing imports --- test/nbrowser/BundleActions.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/nbrowser/BundleActions.ts b/test/nbrowser/BundleActions.ts index 3504cac32f..1f6c2f8564 100644 --- a/test/nbrowser/BundleActions.ts +++ b/test/nbrowser/BundleActions.ts @@ -6,8 +6,7 @@ */ import {assert, driver, Key} from 'mocha-webdriver'; import * as gu from 'test/nbrowser/gristUtils'; -import {setupTestSuite} from 'test/nbrowser/testUtils'; -import {server} from "test/nbrowser/testUtils"; +import {server, setupTestSuite} from 'test/nbrowser/testUtils'; import {SQLiteDB} from 'app/server/lib/SQLiteDB'; import fs from 'fs';