Skip to content

Commit

Permalink
feat(core): Get DefaultSearchPlugin working with new Worker architecture
Browse files Browse the repository at this point in the history
Relates to #115
  • Loading branch information
michaelbromley committed Jun 17, 2019
1 parent 508bafd commit 6ca2ab4
Show file tree
Hide file tree
Showing 14 changed files with 404 additions and 136 deletions.
11 changes: 11 additions & 0 deletions packages/core/e2e/config/test-config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Transport } from '@nestjs/microservices';
import { ADMIN_API_PATH, SHOP_API_PATH } from '@vendure/common/lib/shared-constants';
import path from 'path';

import { DefaultAssetNamingStrategy } from '../../src/config/asset-naming-strategy/default-asset-naming-strategy';
import { DefaultLogger } from '../../src/config/logger/default-logger';
import { LogLevel } from '../../src/config/logger/vendure-logger';
import { VendureConfig } from '../../src/config/vendure-config';

import { TestingAssetPreviewStrategy } from './testing-asset-preview-strategy';
Expand Down Expand Up @@ -52,6 +55,7 @@ export const testConfig: VendureConfig = {
paymentOptions: {
paymentMethodHandlers: [],
},
logger: new DefaultLogger({ level: LogLevel.Error }),
importExportOptions: {
importAssetsDir: path.join(__dirname, '..', 'fixtures/assets'),
},
Expand All @@ -60,4 +64,11 @@ export const testConfig: VendureConfig = {
assetStorageStrategy: new TestingAssetStorageStrategy(),
assetPreviewStrategy: new TestingAssetPreviewStrategy(),
},
workerOptions: {
runInMainProcess: true,
transport: Transport.TCP,
options: {
port: 3051,
},
},
};
37 changes: 33 additions & 4 deletions packages/core/e2e/default-search-plugin.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
ConfigArgType,
CreateCollection,
CreateFacet,
GetRunningJobs,
JobState,
LanguageCode,
SearchFacetValues,
SearchGetPrices,
Expand Down Expand Up @@ -45,7 +47,7 @@ describe('Default search plugin', () => {
customerCount: 1,
},
{
plugins: [new DefaultSearchPlugin({ runInForkedProcess: false })],
plugins: [new DefaultSearchPlugin()],
},
);
await adminClient.init();
Expand Down Expand Up @@ -269,6 +271,7 @@ describe('Default search plugin', () => {
{ id: 'T_3', enabled: false },
],
});
await awaitRunningJobs();
const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(SEARCH_PRODUCTS_SHOP, {
input: {
groupByProduct: false,
Expand Down Expand Up @@ -313,7 +316,7 @@ describe('Default search plugin', () => {
facetValueIds: [],
},
});

await awaitRunningJobs();
const result = await adminClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
SEARCH_PRODUCTS,
{
Expand Down Expand Up @@ -358,7 +361,7 @@ describe('Default search plugin', () => {
},
},
);

await awaitRunningJobs();
const result = await adminClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
SEARCH_PRODUCTS,
{
Expand Down Expand Up @@ -411,7 +414,7 @@ describe('Default search plugin', () => {
],
},
});

await awaitRunningJobs();
const result = await adminClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
SEARCH_PRODUCTS,
{
Expand All @@ -438,6 +441,7 @@ describe('Default search plugin', () => {
value: 50,
},
});
await awaitRunningJobs();
const result = await adminClient.query<SearchGetPrices.Query, SearchGetPrices.Variables>(SEARCH_GET_PRICES, {
input: {
groupByProduct: true,
Expand Down Expand Up @@ -473,6 +477,7 @@ describe('Default search plugin', () => {
{ id: 'T_2', enabled: false },
],
});
await awaitRunningJobs();
const result = await adminClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(SEARCH_PRODUCTS, {
input: {
groupByProduct: true,
Expand All @@ -492,6 +497,7 @@ describe('Default search plugin', () => {
{ id: 'T_4', enabled: false },
],
});
await awaitRunningJobs();
const result = await adminClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(SEARCH_PRODUCTS, {
input: {
groupByProduct: true,
Expand All @@ -512,6 +518,7 @@ describe('Default search plugin', () => {
enabled: false,
},
});
await awaitRunningJobs();
const result = await adminClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(SEARCH_PRODUCTS, {
input: {
groupByProduct: true,
Expand All @@ -525,8 +532,30 @@ describe('Default search plugin', () => {
]);
});
});

/**
* Since the updates to the search index are performed in the background, we need
* to ensure that any running background jobs are completed before continuing certain
* tests.
*/
async function awaitRunningJobs() {
let runningJobs = 0;
do {
const { jobs } = await adminClient.query<GetRunningJobs.Query>(GET_RUNNING_JOBS);
runningJobs = jobs.filter(job => job.state !== JobState.COMPLETED);
} while (runningJobs > 0);
}
});

export const GET_RUNNING_JOBS = gql`
query GetRunningJobs {
jobs {
name
state
}
}
`;

export const SEARCH_PRODUCTS = gql`
query SearchProductsAdmin($input: SearchInput!) {
search(input: $input) {
Expand Down
Loading

0 comments on commit 6ca2ab4

Please sign in to comment.