Skip to content

Commit

Permalink
ci: limit parallelism in tests (#246)
Browse files Browse the repository at this point in the history
* added heap size log to tests

* fixed formatting
  • Loading branch information
sr258 authored and JPSchellenberg committed Nov 10, 2019
1 parent 38c63d2 commit 4fc56e3
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 104 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
"download:content-type-cache": "ts-node scripts/update-real-content-type-cache.ts",
"ci": "npm run build && npm run lint && npm run format:check && npm run test",
"lint": "./node_modules/.bin/tslint --project tsconfig.json --config tslint.json",
"test": "jest --testTimeout=30000",
"test": "jest --testTimeout=30000 --logHeapUsage --maxWorkers=2",
"test:watch": "jest --watch",
"test:e2e": "npm run test:e2e:player",
"test:e2e:player": "./node_modules/.bin/ts-node test/e2e/H5PPlayer.DisplayContent.test.ts",
"test:coverage": "npx jest --collect-coverage --testTimeout=30000",
"test:integration": "npx jest --config jest.integration.config.js --maxWorkers=4",
"format:check": "prettier --check \"{src,test}/**/*.ts\"",
"format": "prettier --write \"{src,test}/**/*.ts\"",
"test:integration": "npx jest --config jest.integration.config.js --maxWorkers=2 --logHeapUsage",
"format:check": "npx prettier --check \"{src,test}/**/*.ts\"",
"format": "npx prettier --write \"{src,test}/**/*.ts\"",
"semantic-release": "semantic-release"
},
"release": {
Expand Down
6 changes: 3 additions & 3 deletions src/ContentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ export default class ContentManager {
const content: ContentParameters = await fsExtra.readJSON(
path.join(packageDirectory, 'content', 'content.json')
);
const otherContentFiles: string[] = (await globPromise(
path.join(packageDirectory, 'content', '**/*.*')
)).filter(
const otherContentFiles: string[] = (
await globPromise(path.join(packageDirectory, 'content', '**/*.*'))
).filter(
(file: string) =>
path.relative(packageDirectory, file) !== 'content.json'
);
Expand Down
12 changes: 6 additions & 6 deletions src/ContentTypeCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ export default class ContentTypeCache {
if (!machineNames || machineNames.length === 0) {
return this.storage.load('contentTypeCache');
}
return (await this.storage.load('contentTypeCache')).filter(
(contentType: HubContentType) =>
machineNames.some(
(machineName: string) =>
machineName === contentType.machineName
)
return (
await this.storage.load('contentTypeCache')
).filter((contentType: HubContentType) =>
machineNames.some(
(machineName: string) => machineName === contentType.machineName
)
);
}

Expand Down
86 changes: 45 additions & 41 deletions src/H5PEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,22 @@ export default class H5PEditor {
', '
)}`
);
return (await Promise.all(
libraryNames.map(async name => {
const lib = LibraryName.fromUberName(name, {
useWhitespace: true
});
return {
languageJson: await this.libraryManager.loadLanguage(
lib,
language
),
name
};
})
)).reduce((builtObject: any, { languageJson, name }) => {
return (
await Promise.all(
libraryNames.map(async name => {
const lib = LibraryName.fromUberName(name, {
useWhitespace: true
});
return {
languageJson: await this.libraryManager.loadLanguage(
lib,
language
),
name
};
})
)
).reduce((builtObject: any, { languageJson, name }) => {
if (languageJson) {
builtObject[name] = JSON.stringify(languageJson);
}
Expand All @@ -206,34 +208,36 @@ export default class H5PEditor {
log.info(
`getting library overview for libraries: ${libraryNames.join(', ')}`
);
return (await Promise.all(
libraryNames
.map(name =>
LibraryName.fromUberName(name, {
useWhitespace: true
return (
await Promise.all(
libraryNames
.map(name =>
LibraryName.fromUberName(name, {
useWhitespace: true
})
)
.filter(lib => lib !== undefined) // we filter out undefined values as Library.creatFromNames returns undefined for invalid names
.map(async lib => {
const loadedLibrary = await this.libraryManager.loadLibrary(
lib
);
if (!loadedLibrary) {
return undefined;
}
return {
majorVersion: loadedLibrary.majorVersion,
metadataSettings: null,
minorVersion: loadedLibrary.minorVersion,
name: loadedLibrary.machineName,
restricted: false,
runnable: loadedLibrary.runnable,
title: loadedLibrary.title,
tutorialUrl: '',
uberName: `${loadedLibrary.machineName} ${loadedLibrary.majorVersion}.${loadedLibrary.minorVersion}`
};
})
)
.filter(lib => lib !== undefined) // we filter out undefined values as Library.creatFromNames returns undefined for invalid names
.map(async lib => {
const loadedLibrary = await this.libraryManager.loadLibrary(
lib
);
if (!loadedLibrary) {
return undefined;
}
return {
majorVersion: loadedLibrary.majorVersion,
metadataSettings: null,
minorVersion: loadedLibrary.minorVersion,
name: loadedLibrary.machineName,
restricted: false,
runnable: loadedLibrary.runnable,
title: loadedLibrary.title,
tutorialUrl: '',
uberName: `${loadedLibrary.machineName} ${loadedLibrary.majorVersion}.${loadedLibrary.minorVersion}`
};
})
)).filter(lib => lib !== undefined); // we filter out undefined values as the last map return undefined values if a library doesn't exist
)
).filter(lib => lib !== undefined); // we filter out undefined values as the last map return undefined values if a library doesn't exist
}

/**
Expand Down
45 changes: 26 additions & 19 deletions src/LibraryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,19 @@ export default class LibraryManager {
public async getInstalled(machineNames?: string[]): Promise<any> {
log.verbose(`checking if libraries ${machineNames} are installed`);
let libraries = await this.libraryStorage.getInstalled(...machineNames);
libraries = (await Promise.all(
libraries.map(async libName => {
const installedLib = InstalledLibrary.fromName(libName);
const info = await this.loadLibrary(libName);
installedLib.patchVersion = info.patchVersion;
installedLib.id = info.libraryId;
installedLib.runnable = info.runnable;
installedLib.title = info.title;
return installedLib;
})
)).sort((lib1, lib2) => lib1.compare(lib2));
libraries = (
await Promise.all(
libraries.map(async libName => {
const installedLib = InstalledLibrary.fromName(libName);
const info = await this.loadLibrary(libName);
installedLib.patchVersion = info.patchVersion;
installedLib.id = info.libraryId;
installedLib.runnable = info.runnable;
installedLib.title = info.title;
return installedLib;
})
)
).sort((lib1, lib2) => lib1.compare(lib2));

const returnObject = {};
for (const library of libraries) {
Expand Down Expand Up @@ -409,14 +411,19 @@ export default class LibraryManager {
', '
)} for ${LibraryName.toUberName(library)}`
);
const missingFiles = (await Promise.all(
requiredFiles.map(async (file: string) => {
return {
path: file,
status: await this.libraryStorage.fileExists(library, file)
};
})
))
const missingFiles = (
await Promise.all(
requiredFiles.map(async (file: string) => {
return {
path: file,
status: await this.libraryStorage.fileExists(
library,
file
)
};
})
)
)
.filter((file: { status: boolean }) => !file.status)
.map((file: { path: string }) => file.path);
if (missingFiles.length > 0) {
Expand Down
7 changes: 3 additions & 4 deletions src/PackageExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,9 @@ export default class PackageExporter {
);
}
if (
!(await this.contentManager.getUserPermissions(
contentId,
user
)).some(p => p === Permission.Download)
!(
await this.contentManager.getUserPermissions(contentId, user)
).some(p => p === Permission.Download)
) {
throw new H5pError(
`You do not have permission to download content with id ${contentId}`
Expand Down
62 changes: 35 additions & 27 deletions test/DependencyGetter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ describe('basic file library manager functionality', () => {
const dependencyGetter = new DependencyGetter(libManager);

expect(
(await dependencyGetter.getDependentLibraries(
[new LibraryName('Lib1', 1, 0)],
{
editor: true,
preloaded: true
}
))
(
await dependencyGetter.getDependentLibraries(
[new LibraryName('Lib1', 1, 0)],
{
editor: true,
preloaded: true
}
)
)
.map(d => LibraryName.toUberName(d))
.sort()
).toMatchObject([
Expand All @@ -33,36 +35,42 @@ describe('basic file library manager functionality', () => {
]);

expect(
(await dependencyGetter.getDependentLibraries(
[new LibraryName('Lib1', 1, 0)],
{
preloaded: true
}
))
(
await dependencyGetter.getDependentLibraries(
[new LibraryName('Lib1', 1, 0)],
{
preloaded: true
}
)
)
.map(d => LibraryName.toUberName(d))
.sort()
).toMatchObject(['Lib1-1.0', 'Lib2-1.0', 'Lib3-1.0', 'Lib5-1.0']);

expect(
(await dependencyGetter.getDependentLibraries(
[new LibraryName('Lib4', 1, 0)],
{
editor: true,
preloaded: true
}
))
(
await dependencyGetter.getDependentLibraries(
[new LibraryName('Lib4', 1, 0)],
{
editor: true,
preloaded: true
}
)
)
.map(d => LibraryName.toUberName(d))
.sort()
).toMatchObject(['Lib4-1.0', 'Lib5-1.0']);

expect(
(await dependencyGetter.getDependentLibraries(
[new LibraryName('Lib5', 1, 0)],
{
editor: true,
preloaded: true
}
))
(
await dependencyGetter.getDependentLibraries(
[new LibraryName('Lib5', 1, 0)],
{
editor: true,
preloaded: true
}
)
)
.map(d => LibraryName.toUberName(d))
.sort()
).toMatchObject(['Lib5-1.0']);
Expand Down

0 comments on commit 4fc56e3

Please sign in to comment.