mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
(core) port some more test/browser tests to newer selenium
Summary: Ports more test/browser tests from *.test.js (run using an old selenium setup) to *.ntest.js (run using newer setup). Weird test failures happened due to a change in timing. Eventually tracked in down to billing changes in one test suite resulting in reloads in another test suite, since it turns out redis pub/sub channels are not scoped to the redis database specified in REDIS_URL, but are global: https://redis.io/docs/manual/pubsub/#database--scoping. Test Plan: Ported tests should run and pass Reviewers: jarek Reviewed By: jarek Differential Revision: https://phab.getgrist.com/D3844
This commit is contained in:
parent
900859854c
commit
cc0e1154d0
@ -130,7 +130,7 @@ import {createAttachmentsIndex, DocStorage, REMOVE_UNUSED_ATTACHMENTS_DELAY} fro
|
|||||||
import {expandQuery} from './ExpandedQuery';
|
import {expandQuery} from './ExpandedQuery';
|
||||||
import {GranularAccess, GranularAccessForBundle} from './GranularAccess';
|
import {GranularAccess, GranularAccessForBundle} from './GranularAccess';
|
||||||
import {OnDemandActions} from './OnDemandActions';
|
import {OnDemandActions} from './OnDemandActions';
|
||||||
import {getLogMetaFromDocSession, timeoutReached} from './serverUtils';
|
import {getLogMetaFromDocSession, getPubSubPrefix, timeoutReached} from './serverUtils';
|
||||||
import {findOrAddAllEnvelope, Sharing} from './Sharing';
|
import {findOrAddAllEnvelope, Sharing} from './Sharing';
|
||||||
import cloneDeep = require('lodash/cloneDeep');
|
import cloneDeep = require('lodash/cloneDeep');
|
||||||
import flatten = require('lodash/flatten');
|
import flatten = require('lodash/flatten');
|
||||||
@ -235,7 +235,10 @@ export class ActiveDoc extends EventEmitter {
|
|||||||
private _redisSubscriber?: RedisClient;
|
private _redisSubscriber?: RedisClient;
|
||||||
|
|
||||||
// Timer for shutting down the ActiveDoc a bit after all clients are gone.
|
// Timer for shutting down the ActiveDoc a bit after all clients are gone.
|
||||||
private _inactivityTimer = new InactivityTimer(() => this.shutdown(), Deps.ACTIVEDOC_TIMEOUT * 1000);
|
private _inactivityTimer = new InactivityTimer(() => {
|
||||||
|
this._log.debug(null, 'inactivity timeout');
|
||||||
|
return this.shutdown();
|
||||||
|
}, Deps.ACTIVEDOC_TIMEOUT * 1000);
|
||||||
private _recoveryMode: boolean = false;
|
private _recoveryMode: boolean = false;
|
||||||
private _shuttingDown: boolean = false;
|
private _shuttingDown: boolean = false;
|
||||||
private _afterShutdownCallback?: () => Promise<void>;
|
private _afterShutdownCallback?: () => Promise<void>;
|
||||||
@ -289,12 +292,14 @@ export class ActiveDoc extends EventEmitter {
|
|||||||
this._gracePeriodStart = gracePeriodStart;
|
this._gracePeriodStart = gracePeriodStart;
|
||||||
|
|
||||||
if (process.env.REDIS_URL && billingAccount) {
|
if (process.env.REDIS_URL && billingAccount) {
|
||||||
const channel = `billingAccount-${billingAccount.id}-product-changed`;
|
const prefix = getPubSubPrefix();
|
||||||
|
const channel = `${prefix}-billingAccount-${billingAccount.id}-product-changed`;
|
||||||
this._redisSubscriber = createClient(process.env.REDIS_URL);
|
this._redisSubscriber = createClient(process.env.REDIS_URL);
|
||||||
this._redisSubscriber.subscribe(channel);
|
this._redisSubscriber.subscribe(channel);
|
||||||
this._redisSubscriber.on("message", async () => {
|
this._redisSubscriber.on("message", async () => {
|
||||||
// A product change has just happened in Billing.
|
// A product change has just happened in Billing.
|
||||||
// Reload the doc (causing connected clients to reload) to ensure everyone sees the effect of the change.
|
// Reload the doc (causing connected clients to reload) to ensure everyone sees the effect of the change.
|
||||||
|
this._log.debug(null, 'reload after product change');
|
||||||
await this.reloadDoc();
|
await this.reloadDoc();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -631,6 +636,7 @@ export class ActiveDoc extends EventEmitter {
|
|||||||
if (!await this._granularAccess.isOwner(docSession)) {
|
if (!await this._granularAccess.isOwner(docSession)) {
|
||||||
throw new ApiError('Only owners can replace a document.', 403);
|
throw new ApiError('Only owners can replace a document.', 403);
|
||||||
}
|
}
|
||||||
|
this._log.debug(docSession, 'ActiveDoc.replace starting shutdown');
|
||||||
return this.shutdown({
|
return this.shutdown({
|
||||||
afterShutdown: () => this._docManager.storageManager.replace(this.docName, source)
|
afterShutdown: () => this._docManager.storageManager.replace(this.docName, source)
|
||||||
});
|
});
|
||||||
@ -1297,6 +1303,7 @@ export class ActiveDoc extends EventEmitter {
|
|||||||
* browser clients to reopen it.
|
* browser clients to reopen it.
|
||||||
*/
|
*/
|
||||||
public async reloadDoc(docSession?: DocSession) {
|
public async reloadDoc(docSession?: DocSession) {
|
||||||
|
this._log.debug(docSession || null, 'ActiveDoc.reloadDoc starting shutdown');
|
||||||
return this.shutdown();
|
return this.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,6 +235,7 @@ export class DocManager extends EventEmitter {
|
|||||||
if (docPromise) {
|
if (docPromise) {
|
||||||
// Call activeDoc's shutdown method first, to remove the doc from internal structures.
|
// Call activeDoc's shutdown method first, to remove the doc from internal structures.
|
||||||
const doc: ActiveDoc = await docPromise;
|
const doc: ActiveDoc = await docPromise;
|
||||||
|
log.debug('DocManager.deleteDoc starting activeDoc shutdown', docName);
|
||||||
await doc.shutdown();
|
await doc.shutdown();
|
||||||
}
|
}
|
||||||
await this.storageManager.deleteDoc(docName, deletePermanently);
|
await this.storageManager.deleteDoc(docName, deletePermanently);
|
||||||
@ -368,8 +369,12 @@ export class DocManager extends EventEmitter {
|
|||||||
* Shut down all open docs. This is called, in particular, on server shutdown.
|
* Shut down all open docs. This is called, in particular, on server shutdown.
|
||||||
*/
|
*/
|
||||||
public async shutdownAll() {
|
public async shutdownAll() {
|
||||||
await Promise.all(Array.from(this._activeDocs.values(),
|
await Promise.all(Array.from(
|
||||||
adocPromise => adocPromise.then(adoc => adoc.shutdown())));
|
this._activeDocs.values(),
|
||||||
|
adocPromise => adocPromise.then(async adoc => {
|
||||||
|
log.debug('DocManager.shutdownAll starting activeDoc shutdown', adoc.docName);
|
||||||
|
await adoc.shutdown();
|
||||||
|
})));
|
||||||
try {
|
try {
|
||||||
await this.storageManager.closeStorage();
|
await this.storageManager.closeStorage();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -471,6 +476,7 @@ export class DocManager extends EventEmitter {
|
|||||||
if (activeDoc && activeDoc.recoveryMode !== wantRecoveryMode && await activeDoc.isOwner(docSession)) {
|
if (activeDoc && activeDoc.recoveryMode !== wantRecoveryMode && await activeDoc.isOwner(docSession)) {
|
||||||
// shutting doc down to have a chance to re-open in the correct mode.
|
// shutting doc down to have a chance to re-open in the correct mode.
|
||||||
// TODO: there could be a battle with other users opening it in a different mode.
|
// TODO: there could be a battle with other users opening it in a different mode.
|
||||||
|
log.debug('DocManager._fetchPossiblyMutedDoc starting activeDoc shutdown', docName);
|
||||||
await activeDoc.shutdown();
|
await activeDoc.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -480,6 +480,7 @@ export class Sharing {
|
|||||||
} catch(rollbackExc) {
|
} catch(rollbackExc) {
|
||||||
this._log.error(docSession, "Failed to apply undo of rejected action", rollbackExc.message);
|
this._log.error(docSession, "Failed to apply undo of rejected action", rollbackExc.message);
|
||||||
await accessControl.finishedBundle();
|
await accessControl.finishedBundle();
|
||||||
|
this._log.debug(docSession, "Sharing._applyActionsToDataEngine starting ActiveDoc.shutdown");
|
||||||
await this._activeDoc.shutdown();
|
await this._activeDoc.shutdown();
|
||||||
throw rollbackExc;
|
throw rollbackExc;
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ export function getSupportedEngineChoices(): EngineCode[]|undefined {
|
|||||||
* Returns a promise that resolves in the given number of milliseconds or rejects
|
* Returns a promise that resolves in the given number of milliseconds or rejects
|
||||||
* when the given signal is raised.
|
* when the given signal is raised.
|
||||||
*/
|
*/
|
||||||
export function delayAbort(msec: number, signal?: AbortSignal): Promise<void> {
|
export function delayAbort(msec: number, signal?: AbortSignal): Promise<void> {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
let resolved = false;
|
let resolved = false;
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
@ -198,3 +198,20 @@ export function getSupportedEngineChoices(): EngineCode[]|undefined {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For a Redis URI, we expect no path component, or a path component
|
||||||
|
* that is an integer database number. We'd like to scope pub/sub to
|
||||||
|
* individual databases. Redis doesn't do that, so we construct a
|
||||||
|
* key prefix to have the same effect.
|
||||||
|
* https://redis.io/docs/manual/pubsub/#database--scoping
|
||||||
|
*/
|
||||||
|
export function getPubSubPrefix(): string {
|
||||||
|
const redisUrl = process.env.REDIS_URL;
|
||||||
|
if (!redisUrl) { return 'db-x'; }
|
||||||
|
const dbNumber = new URL(redisUrl).pathname.replace(/^\//, '');
|
||||||
|
if (dbNumber.match(/[^0-9]/)) {
|
||||||
|
throw new Error('REDIS_URL has an unexpected structure');
|
||||||
|
}
|
||||||
|
return `db-${dbNumber}`;
|
||||||
|
}
|
||||||
|
@ -60,6 +60,7 @@ export const isOnLoginPage = homeUtil.isOnLoginPage.bind(homeUtil);
|
|||||||
export const isOnGristLoginPage = homeUtil.isOnLoginPage.bind(homeUtil);
|
export const isOnGristLoginPage = homeUtil.isOnLoginPage.bind(homeUtil);
|
||||||
export const checkLoginPage = homeUtil.checkLoginPage.bind(homeUtil);
|
export const checkLoginPage = homeUtil.checkLoginPage.bind(homeUtil);
|
||||||
export const checkGristLoginPage = homeUtil.checkGristLoginPage.bind(homeUtil);
|
export const checkGristLoginPage = homeUtil.checkGristLoginPage.bind(homeUtil);
|
||||||
|
export const copyDoc = homeUtil.copyDoc.bind(homeUtil);
|
||||||
|
|
||||||
export const fixturesRoot: string = testUtils.fixturesRoot;
|
export const fixturesRoot: string = testUtils.fixturesRoot;
|
||||||
|
|
||||||
@ -758,10 +759,14 @@ export async function waitForDocMenuToLoad(): Promise<void> {
|
|||||||
|
|
||||||
export async function waitToPass(check: () => Promise<void>, timeMs: number = 4000) {
|
export async function waitToPass(check: () => Promise<void>, timeMs: number = 4000) {
|
||||||
try {
|
try {
|
||||||
|
let delay: number = 10;
|
||||||
await driver.wait(async () => {
|
await driver.wait(async () => {
|
||||||
try {
|
try {
|
||||||
await check();
|
await check();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
// Throttle operations a little bit.
|
||||||
|
await driver.sleep(delay);
|
||||||
|
if (delay < 50) { delay += 10; }
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -1714,6 +1719,7 @@ export async function openDocDropdown(docNameOrRow: string|WebElement): Promise<
|
|||||||
export async function openAccessRulesDropdown(): Promise<void> {
|
export async function openAccessRulesDropdown(): Promise<void> {
|
||||||
await driver.find('.test-tools-access-rules').mouseMove();
|
await driver.find('.test-tools-access-rules').mouseMove();
|
||||||
await driver.find('.test-tools-access-rules-trigger').mouseMove().click();
|
await driver.find('.test-tools-access-rules-trigger').mouseMove().click();
|
||||||
|
await driver.findWait('.grist-floating-menu', 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function editOrgAcls(): Promise<void> {
|
export async function editOrgAcls(): Promise<void> {
|
||||||
@ -1884,6 +1890,7 @@ export enum TestUserEnum {
|
|||||||
user2 = 'charon',
|
user2 = 'charon',
|
||||||
user3 = 'kiwi',
|
user3 = 'kiwi',
|
||||||
user4 = 'ham',
|
user4 = 'ham',
|
||||||
|
userz = 'userz', // a user for old tests, that doesn't overlap with others.
|
||||||
owner = 'chimpy',
|
owner = 'chimpy',
|
||||||
anon = 'anon',
|
anon = 'anon',
|
||||||
support = 'support',
|
support = 'support',
|
||||||
|
Loading…
Reference in New Issue
Block a user