Skip to content

Commit

Permalink
[Tests] add more tests for optimized healthcheck
Browse files Browse the repository at this point in the history
Add more tests to verify logic added here:
opensearch-project#2277

That makes a request for nodes info with a list of node ids.

Issue:
n/a

Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed Sep 9, 2022
1 parent 77af7f9 commit 5dd8ac4
Showing 1 changed file with 160 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ describe('pollOpenSearchNodesVersion', () => {
});

it('returns compatibility results and isCompatible=true with filters', (done) => {
expect.assertions(2);
expect.assertions(3);
const target = {
cluster_id: '0',
attribute: 'foo',
Expand Down Expand Up @@ -293,6 +293,11 @@ describe('pollOpenSearchNodesVersion', () => {
.pipe(take(1))
.subscribe({
next: (result) => {
expect(internalClient.nodes.info).toBeCalledWith({
node_id: '_local',
metric: 'process',
filter_path: ['nodes.*.version', 'nodes.*.http.publish_address', 'nodes.*.ip'],
});
expect(result).toEqual(
mapNodesVersionCompatibility(filteredNodes, OPENSEARCH_DASHBOARDS_VERSION, false)
);
Expand All @@ -304,7 +309,7 @@ describe('pollOpenSearchNodesVersion', () => {
});

it('returns compatibility results and isCompatible=false with filters', (done) => {
expect.assertions(2);
expect.assertions(3);
const target = {
cluster_id: '0',
attribute: 'foo',
Expand Down Expand Up @@ -346,6 +351,11 @@ describe('pollOpenSearchNodesVersion', () => {
.pipe(take(1))
.subscribe({
next: (result) => {
expect(internalClient.nodes.info).toBeCalledWith({
node_id: '_local',
metric: 'process',
filter_path: ['nodes.*.version', 'nodes.*.http.publish_address', 'nodes.*.ip'],
});
expect(result).toEqual(
mapNodesVersionCompatibility(filteredNodes, OPENSEARCH_DASHBOARDS_VERSION, false)
);
Expand All @@ -356,6 +366,154 @@ describe('pollOpenSearchNodesVersion', () => {
});
});

it('returns compatibility results and isCompatible=true with filters and multiple cluster ids', (done) => {
expect.assertions(3);
const nodes = {} as any;
nodes['node-0'] = {
version: '5.1.0',
http: {
publish_address: 'http_address',
},
ip: 'ip',
attributes: {
cluster_id: '0',
custom_attribute: 'foo',
},
};
nodes['node-1'] = {
version: '5.1.0',
http: {
publish_address: 'http_address',
},
ip: 'ip',
attributes: {
cluster_id: '1',
custom_attribute: 'foo',
},
};
nodes['node-2'] = {
version: '6.2.0',
http: {
publish_address: 'http_address',
},
ip: 'ip',
attributes: {
cluster_id: '2',
custom_attribute: 'bar',
},
};
const filteredNodes = nodes;
delete filteredNodes['node-2'];

// @ts-expect-error we need to return an incompatible type to use the testScheduler here
internalClient.cluster.state.mockReturnValueOnce({ body: { nodes } });

nodeInfosSuccessOnce({ nodes: filteredNodes });

pollOpenSearchNodesVersion({
internalClient,
optimizedHealthcheck: { id: 'cluster_id', filters: { custom_attribute: 'bar' } },
opensearchVersionCheckInterval: 1,
ignoreVersionMismatch: false,
opensearchDashboardsVersion: OPENSEARCH_DASHBOARDS_VERSION,
log: mockLogger,
})
.pipe(take(1))
.subscribe({
next: (result) => {
expect(internalClient.nodes.info).toBeCalledWith({
node_id: ['node-0', 'node-1'],
metric: 'process',
filter_path: ['nodes.*.version', 'nodes.*.http.publish_address', 'nodes.*.ip'],
});
expect(result).toEqual(
mapNodesVersionCompatibility(
{ nodes: filteredNodes },
OPENSEARCH_DASHBOARDS_VERSION,
false
)
);
expect(result.isCompatible).toBe(true);
},
complete: done,
error: done,
});
});

it('returns compatibility results and isCompatible=false with filters and multiple cluster ids', (done) => {
expect.assertions(3);
const nodes = {} as any;
nodes['node-0'] = {
version: '5.1.0',
http: {
publish_address: 'http_address',
},
ip: 'ip',
attributes: {
cluster_id: '0',
custom_attribute: 'foo',
},
};
nodes['node-1'] = {
version: '6.2.0',
http: {
publish_address: 'http_address',
},
ip: 'ip',
attributes: {
cluster_id: '1',
custom_attribute: 'foo',
},
};
nodes['node-2'] = {
version: '6.2.0',
http: {
publish_address: 'http_address',
},
ip: 'ip',
attributes: {
cluster_id: '2',
custom_attribute: 'bar',
},
};
const filteredNodes = nodes;
delete filteredNodes['node-2'];

// @ts-expect-error we need to return an incompatible type to use the testScheduler here
internalClient.cluster.state.mockReturnValueOnce({ body: { nodes } });

nodeInfosSuccessOnce({ nodes: filteredNodes });

pollOpenSearchNodesVersion({
internalClient,
optimizedHealthcheck: { id: 'cluster_id', filters: { custom_attribute: 'bar' } },
opensearchVersionCheckInterval: 1,
ignoreVersionMismatch: false,
opensearchDashboardsVersion: OPENSEARCH_DASHBOARDS_VERSION,
log: mockLogger,
})
.pipe(take(1))
.subscribe({
next: (result) => {
expect(internalClient.nodes.info).toBeCalledWith({
node_id: ['node-0', 'node-1'],
metric: 'process',
filter_path: ['nodes.*.version', 'nodes.*.http.publish_address', 'nodes.*.ip'],
});
expect(result).toEqual(
mapNodesVersionCompatibility(
{ nodes: filteredNodes },
OPENSEARCH_DASHBOARDS_VERSION,
false
)
);
expect(result.isCompatible).toBe(false);
},
complete: done,
error: done,
});
});

it('only emits if the node versions changed since the previous poll', (done) => {
expect.assertions(4);
nodeInfosSuccessOnce(createNodes('5.1.0', '5.2.0', '5.0.0')); // emit
Expand Down

0 comments on commit 5dd8ac4

Please sign in to comment.