Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delay between render tests #1938

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/util/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export const WEBP_HANDLER_URL = 'https://gist.githubusercontent.com/rgaudin/60bb
export const MAX_FILE_DOWNLOAD_RETRIES = 5
export const BLACKLISTED_NS = ['Story'] // 'Story' Wikipedia namespace is content, but not indgestable by Parsoid https://github.com/openzim/mwoffliner/issues/1853
export const RENDERERS_LIST = ['WikimediaDesktop', 'VisualEditor', 'WikimediaMobile']
export const RENDER_TEST_DELAY = 1000
4 changes: 3 additions & 1 deletion test/e2e/extra.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { join } from 'path'
import { execa } from 'execa'
import 'dotenv/config.js'
import { jest } from '@jest/globals'
import { RENDERERS_LIST } from '../../src/util/const.js'
import { sleep } from '../util.js'
import { RENDERERS_LIST, RENDER_TEST_DELAY } from '../../src/util/const.js'

jest.setTimeout(20000)

Expand Down Expand Up @@ -67,6 +68,7 @@ describe('Extra', () => {
const redisScan = await execa('redis-cli --scan', { shell: true })
// Redis has been cleared
expect(redisScan.stdout).toEqual('')
await sleep(RENDER_TEST_DELAY)
})
}
})
5 changes: 3 additions & 2 deletions test/testAllRenders.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as logger from '../src/Logger.js'
import * as mwoffliner from '../src/mwoffliner.lib.js'
import { execa } from 'execa'
import { RENDERERS_LIST } from '../src/util/const.js'
import { zimcheckAvailable, zimdumpAvailable } from './util.js'
import { RENDERERS_LIST, RENDER_TEST_DELAY } from '../src/util/const.js'
import { zimcheckAvailable, zimdumpAvailable, sleep } from './util.js'

interface Parameters {
mwUrl: string
Expand Down Expand Up @@ -56,5 +56,6 @@ export async function testAllRenders(parameters: Parameters, callback) {
outFiles[0].testId = testId
outFiles[0].renderer = renderer
await callback(outFiles)
await sleep(RENDER_TEST_DELAY)
}
}
27 changes: 3 additions & 24 deletions test/unit/downloader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import domino from 'domino'
import { WikimediaDesktopRenderer } from '../../src/renderers/wikimedia-desktop.renderer.js'
import { VisualEditorRenderer } from '../../src/renderers/visual-editor.renderer.js'
import { WikimediaMobileRenderer } from '../../src/renderers/wikimedia-mobile.renderer.js'
import { RENDERERS_LIST } from '../../src/util/const.js'
import { RENDERERS_LIST, RENDER_TEST_DELAY } from '../../src/util/const.js'
import { sleep } from '../util.js'

jest.setTimeout(200000)

Expand Down Expand Up @@ -187,29 +188,6 @@ describe('Downloader class', () => {
)
expect(PaginatedArticle.length).toBeGreaterThan(100)
})

test('getArticle response status for non-existent article id is 404 for WikimediaDesktop render', async () => {
const articleId = 'NeverExistingArticle'
const articleUrl = getArticleUrl(downloader, dump, articleId)
const articleDetail = {
title: articleId,
missing: '',
}
const _moduleDependencies = await downloader.getModuleDependencies(articleDetail.title)
await expect(
downloader.getArticle(
downloader.webp,
_moduleDependencies,
'NeverExistingArticle',
RedisStore.articleDetailXId,
wikimediaDesktopRenderer,
articleUrl,
dump,
articleDetail,
dump.isMainPage(articleId),
),
).rejects.toThrowError(new Error('Request failed with status code 404'))
})
})

describe('getArticle method', () => {
Expand Down Expand Up @@ -255,6 +233,7 @@ describe('Downloader class', () => {
dump.isMainPage(articleId),
),
).rejects.toThrowError(new Error('Request failed with status code 404'))
await sleep(RENDER_TEST_DELAY)
})
}
})
Expand Down
8 changes: 6 additions & 2 deletions test/unit/saveArticles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import domino from 'domino'

import RedisStore from '../../src/RedisStore.js'
import { startRedis, stopRedis } from './bootstrap.js'
import { setupScrapeClasses } from '../util.js'
import { setupScrapeClasses, sleep } from '../util.js'
import { saveArticles } from '../../src/util/saveArticles.js'
import { ZimArticle } from '@openzim/libzim'
import { mwRetToArticleDetail, DELETED_ARTICLE_ERROR } from '../../src/util/index.js'
Expand All @@ -11,7 +11,7 @@ import { getArticleUrl } from '../../src/util/saveArticles.js'
import { WikimediaDesktopRenderer } from '../../src/renderers/wikimedia-desktop.renderer.js'
import { VisualEditorRenderer } from '../../src/renderers/visual-editor.renderer.js'
import { WikimediaMobileRenderer } from '../../src/renderers/wikimedia-mobile.renderer.js'
import { RENDERERS_LIST } from '../../src/util/const.js'
import { RENDERERS_LIST, RENDER_TEST_DELAY } from '../../src/util/const.js'

jest.setTimeout(40000)

Expand Down Expand Up @@ -87,6 +87,7 @@ describe('saveArticles', () => {
expect(articleDoc.querySelector('meta[name="geo.position"]')?.getAttribute('content')).toEqual('51.50722222;-0.1275')
// Check if header exists
expect(articleDoc.querySelector('h1.article-header, h1.pcs-edit-section-title')).toBeTruthy()
await sleep(RENDER_TEST_DELAY)
})

test(`Check nodet article for en.wikipedia.org using ${renderer} renderer`, async () => {
Expand Down Expand Up @@ -118,6 +119,7 @@ describe('saveArticles', () => {
const leadSection = sections[0]
expect(sections.length).toEqual(1)
expect(leadSection.getAttribute('data-mw-section-id')).toEqual('0')
await sleep(RENDER_TEST_DELAY)
})

test(`Load main page and check that it is without header using ${renderer} renderer`, async () => {
Expand All @@ -144,6 +146,7 @@ describe('saveArticles', () => {
)
const articleDoc = domino.createDocument(result[0].html)
expect(articleDoc.querySelector('h1.article-header')).toBeFalsy()
await sleep(RENDER_TEST_DELAY)
})

test(`--customFlavour using ${renderer} renderer`, async () => {
Expand Down Expand Up @@ -211,6 +214,7 @@ describe('saveArticles', () => {
expect(ParisDocument.querySelector('#PRE_PROCESSOR')).toBeDefined()
// Prague was correctly post-processed
expect(PragueDocument.querySelector('#POST_PROCESSOR')).toBeDefined()
await sleep(RENDER_TEST_DELAY)
})
}

Expand Down
5 changes: 3 additions & 2 deletions test/unit/treatments/article.treatment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import domino from 'domino'
import RedisStore from '../../../src/RedisStore.js'
import { ZimArticle } from '@openzim/libzim'
import { mwRetToArticleDetail } from '../../../src/util/mw-api.js'
import { setupScrapeClasses } from '../../util.js'
import { setupScrapeClasses, sleep } from '../../util.js'
import { startRedis, stopRedis } from '../bootstrap.js'
import { saveArticles } from '../../../src/util/saveArticles.js'
import { jest } from '@jest/globals'
import { getArticleUrl } from '../../../src/util/saveArticles.js'
import { WikimediaDesktopRenderer } from '../../../src/renderers/wikimedia-desktop.renderer.js'
import { WikimediaMobileRenderer } from '../../../src/renderers/wikimedia-mobile.renderer.js'
import { VisualEditorRenderer } from '../../../src/renderers/visual-editor.renderer.js'
import { RENDERERS_LIST } from '../../../src/util/const.js'
import { RENDERERS_LIST, RENDER_TEST_DELAY } from '../../../src/util/const.js'

jest.setTimeout(10000)

Expand Down Expand Up @@ -91,6 +91,7 @@ describe('ArticleTreatment', () => {
expect(articleDoc.querySelector('meta[name="geo.position"]')).toBeDefined()
// Geo Position data is correct
expect(articleDoc.querySelector('meta[name="geo.position"]')?.getAttribute('content')).toEqual('51.50722222;-0.1275')
await sleep(RENDER_TEST_DELAY)
})
}
})