Browse Source

fix(dev-server): Fix load tests and populate script

Michael Bromley 6 years ago
parent
commit
4fd4d1ae48

+ 1 - 0
packages/dev-server/.gitignore

@@ -6,4 +6,5 @@ vendure-import-error.log
 load-testing/data-sources/products*.csv
 load-testing/results/*.json
 load-testing/results/*.csv
+load-testing/static/assets
 dev-config-override.ts

+ 0 - 1
packages/dev-server/load-testing/graphql/shop/deep-query.graphql

@@ -44,7 +44,6 @@
                     value
                 }
                 code
-                description
             }
             featuredAsset {
                 id

+ 7 - 2
packages/dev-server/load-testing/init-load-test.ts

@@ -45,7 +45,7 @@ if (require.main === module) {
                     )
                     .then(async app => {
                         console.log('populating customers...');
-                        await populateCustomers(10, config as any, true);
+                        await populateCustomers(10, config, true);
                         return app.close();
                     });
             } else {
@@ -174,7 +174,12 @@ function generateMockData(productCount: number, writeFn: (row: string[]) => void
 }
 
 function getCategoryNames() {
-    const allNames = initialData.collections.reduce((all, c) => [...all, ...c.facetNames], [] as string[]);
+    const allNames = new Set<string>();
+    for (const collection of initialData.collections) {
+        for (const filter of collection.filters || []) {
+            filter.args.facetValueNames.forEach(name => allNames.add(name));
+        }
+    }
     return Array.from(new Set(allNames));
 }
 

+ 29 - 8
packages/dev-server/load-testing/load-test-config.ts

@@ -1,12 +1,19 @@
 /* tslint:disable:no-console */
-import { VendureConfig } from '@vendure/core';
+import { AssetServerPlugin } from '@vendure/asset-server-plugin';
+import {
+    DefaultLogger,
+    DefaultSearchPlugin,
+    examplePaymentHandler,
+    LogLevel,
+    mergeConfig,
+    VendureConfig,
+} from '@vendure/core';
+import { defaultConfig } from '@vendure/core/dist/config/default-config';
 import path from 'path';
 
-import { devConfig } from '../dev-config';
-
 export function getMysqlConnectionOptions(count: number) {
     return {
-        type: 'mysql',
+        type: 'mysql' as const,
         host: '192.168.99.100',
         port: 3306,
         username: 'root',
@@ -15,10 +22,13 @@ export function getMysqlConnectionOptions(count: number) {
     };
 }
 
-export function getLoadTestConfig(tokenMethod: 'cookie' | 'bearer'): VendureConfig {
+export function getLoadTestConfig(tokenMethod: 'cookie' | 'bearer'): Required<VendureConfig> {
     const count = getProductCount();
-    return {
-        ...devConfig as any,
+    return mergeConfig(defaultConfig, {
+        paymentOptions: {
+            paymentMethodHandlers: [examplePaymentHandler],
+        },
+        logger: new DefaultLogger({ level: LogLevel.Info }),
         dbConnectionOptions: getMysqlConnectionOptions(count),
         authOptions: {
             tokenMethod,
@@ -27,8 +37,19 @@ export function getLoadTestConfig(tokenMethod: 'cookie' | 'bearer'): VendureConf
         importExportOptions: {
             importAssetsDir: path.join(__dirname, './data-sources'),
         },
+        workerOptions: {
+            runInMainProcess: true,
+        },
         customFields: {},
-    };
+        plugins: [
+            AssetServerPlugin.init({
+                assetUploadDir: path.join(__dirname, 'static/assets'),
+                route: 'assets',
+                port: 5002,
+            }),
+            DefaultSearchPlugin,
+        ],
+    });
 }
 
 export function getProductCsvFilePath() {

+ 0 - 0
packages/dev-server/load-testing/static/.gitkeep


+ 20 - 17
packages/dev-server/populate-dev-server.ts

@@ -1,7 +1,8 @@
 // tslint:disable-next-line:no-reference
 /// <reference path="../core/typings.d.ts" />
-import { bootstrap, VendureConfig } from '@vendure/core';
+import { bootstrap, mergeConfig, VendureConfig } from '@vendure/core';
 import { populate } from '@vendure/core/cli/populate';
+import { defaultConfig } from '@vendure/core/dist/config/default-config';
 import { clearAllTables, populateCustomers } from '@vendure/testing';
 import path from 'path';
 
@@ -16,21 +17,23 @@ import { devConfig } from './dev-config';
  */
 if (require.main === module) {
     // Running from command line
-    const populateConfig: VendureConfig = {
-        ...(devConfig as any),
-        authOptions: {
-            tokenMethod: 'bearer',
-            requireVerification: false,
-        },
-        importExportOptions: {
-            importAssetsDir: path.join(__dirname, '../core/mock-data/assets'),
-        },
-        workerOptions: {
-            runInMainProcess: true,
-        },
-        customFields: {},
-    };
-    clearAllTables(populateConfig as any, true)
+    const populateConfig = mergeConfig(
+        defaultConfig,
+        mergeConfig(devConfig, {
+            authOptions: {
+                tokenMethod: 'bearer',
+                requireVerification: false,
+            },
+            importExportOptions: {
+                importAssetsDir: path.join(__dirname, '../core/mock-data/assets'),
+            },
+            workerOptions: {
+                runInMainProcess: true,
+            },
+            customFields: {},
+        }),
+    );
+    clearAllTables(populateConfig, true)
         .then(() =>
             populate(
                 () => bootstrap(populateConfig),
@@ -40,7 +43,7 @@ if (require.main === module) {
         )
         .then(async app => {
             console.log('populating customers...');
-            await populateCustomers(10, populateConfig as any, true);
+            await populateCustomers(10, populateConfig, true);
             return app.close();
         })
         .then(