Skip to content

Commit

Permalink
Make the list RSEs pipeline element discard results with errors and c…
Browse files Browse the repository at this point in the history
…over this by a test
  • Loading branch information
MytsV authored and maany committed Nov 26, 2024
1 parent 80d3321 commit 9c1513f
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ export default class GetRSEPipelineElement extends BaseStreamingPostProcessingPi
return errorModel;
}

transformResponseModel(responseModel: ListRSEsResponse, dto: RSEDetailsDTO): ListRSEsResponse {
transformResponseModel(responseModel: ListRSEsResponse, dto: RSEDetailsDTO): ListRSEsResponse | ListRSEsError {
if (dto.status === 'error') {
return {
status: 'error',
message: '',
name: '',
code: 500,
};
}
responseModel.id = dto.id;
responseModel.deterministic = dto.deterministic;
responseModel.rse_type = dto.rse_type;
Expand Down
186 changes: 125 additions & 61 deletions test/api/rse/list-rses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,78 @@ import { MockHttpStreamableResponseFactory } from 'test/fixtures/http-fixtures';
import MockRucioServerFactory, { MockEndpoint } from 'test/fixtures/rucio-server';

describe('List RSEs Feature tests', () => {
beforeEach(() => {
fetchMock.doMock();
const rseStream = Readable.from([JSON.stringify({ rse: 'XRD1' })].join('\n'));

const xrd1 = JSON.stringify({
availability_delete: true,
availability_read: true,
availability_write: true,
deterministic: true,
domain: ['lan', 'wan'],
id: '464cd7656db842c78261bcc2a087bbcb',
lfn2pfn_algorithm: 'hash',
protocols: [
{
hostname: 'xrd1',
scheme: 'root',
port: 1094,
prefix: '//rucio',
impl: 'rucio.rse.protocols.xrootd.Default',
domains: {
lan: {
read: 1,
write: 1,
delete: 1,
},
wan: {
read: 1,
write: 1,
delete: 1,
third_party_copy_read: 1,
third_party_copy_write: 1,
},
const rseStream = Readable.from([JSON.stringify({ rse: 'XRD1' })].join('\n'));

const xrd1 = JSON.stringify({
availability_delete: true,
availability_read: true,
availability_write: true,
deterministic: true,
domain: ['lan', 'wan'],
id: '464cd7656db842c78261bcc2a087bbcb',
lfn2pfn_algorithm: 'hash',
protocols: [
{
hostname: 'xrd1',
scheme: 'root',
port: 1094,
prefix: '//rucio',
impl: 'rucio.rse.protocols.xrootd.Default',
domains: {
lan: {
read: 1,
write: 1,
delete: 1,
},
wan: {
read: 1,
write: 1,
delete: 1,
third_party_copy_read: 1,
third_party_copy_write: 1,
},
extended_attributes: null,
},
],
qos_class: null,
rse: 'XRD1',
rse_type: 'DISK',
sign_url: null,
staging_area: false,
verify_checksum: true,
volatile: false,
read_protocol: 1,
write_protocol: 1,
delete_protocol: 1,
third_party_copy_read_protocol: 1,
third_party_copy_write_protocol: 1,
availability: 7,
});
extended_attributes: null,
},
],
qos_class: null,
rse: 'XRD1',
rse_type: 'DISK',
sign_url: null,
staging_area: false,
verify_checksum: true,
volatile: false,
read_protocol: 1,
write_protocol: 1,
delete_protocol: 1,
third_party_copy_read_protocol: 1,
third_party_copy_write_protocol: 1,
availability: 7,
});

beforeEach(() => {
fetchMock.doMock();
});

afterEach(() => {
fetchMock.dontMock();
});

it('should return with INVALID RSE EXPRESSION error if rseExpression is undefined', async () => {
const res = MockHttpStreamableResponseFactory.getMockResponse();
const controller = appContainer.get<BaseController<ListRSEsControllerParameters, ListRSEsRequest>>(CONTROLLERS.LIST_RSES);
const controllerParams: ListRSEsControllerParameters = {
rucioAuthToken: MockRucioServerFactory.VALID_RUCIO_TOKEN,
response: res as unknown as NextApiResponse,
rseExpression: '',
};

await controller.execute(controllerParams);
const data = await res._getJSONData();
expect(data.status).toBe('error');
expect(data.message).toBe('RSE Expression is undefined or an empty string');
});
it('should list rses as a stream', async () => {
const listRSEsEndpoint: MockEndpoint = {
url: `${MockRucioServerFactory.RUCIO_HOST}/rses/?expression=XRD1`,
method: 'GET',
Expand All @@ -85,34 +107,75 @@ describe('List RSEs Feature tests', () => {
},
};
MockRucioServerFactory.createMockRucioServer(true, [listRSEsEndpoint, getXRD1Endpoint]);
});

afterEach(() => {
fetchMock.dontMock();
});

it('should return with INVALID RSE EXPRESSION error if rseExpression is undefined', async () => {
const res = MockHttpStreamableResponseFactory.getMockResponse();

const controller = appContainer.get<BaseController<ListRSEsControllerParameters, ListRSEsRequest>>(CONTROLLERS.LIST_RSES);
const controllerParams: ListRSEsControllerParameters = {
rucioAuthToken: MockRucioServerFactory.VALID_RUCIO_TOKEN,
response: res as unknown as NextApiResponse,
rseExpression: '',
rseExpression: 'XRD1',
};

await controller.execute(controllerParams);
const data = await res._getJSONData();
expect(data.status).toBe('error');
expect(data.message).toBe('RSE Expression is undefined or an empty string');

const receivedData: any[] = [];
const onData = (data: any) => {
receivedData.push(JSON.parse(data));
};

const done = new Promise<void>((resolve, reject) => {
res.on('data', onData);
res.on('end', () => {
res.off('data', onData);
resolve();
});
res.on('error', err => {
res.off('data', onData);
reject(err);
});
});

await done;

expect(receivedData.length).toEqual(1);
expect(receivedData[0].id).toEqual('464cd7656db842c78261bcc2a087bbcb');
expect(receivedData[0].rse_type).toEqual(RSEType.DISK);
});
it('should list rses as a stream', async () => {
it('should return an error for RSEs which status cannot be fetched', async () => {
const listRSEsEndpoint: MockEndpoint = {
url: `${MockRucioServerFactory.RUCIO_HOST}/rses/?expression=*`,
method: 'GET',
includes: 'rses?expression=*',
response: {
status: 200,
headers: {
'Content-Type': 'application/x-json-stream',
},
body: Readable.from([JSON.stringify({ rse: 'XRD1' }), JSON.stringify({ rse: 'XRD2' })].join('\n')),
},
};
const getXRD1Endpoint: MockEndpoint = {
url: `${MockRucioServerFactory.RUCIO_HOST}/rses/XRD1`,
method: 'GET',
includes: 'rses/XRD1',
response: {
status: 200,
headers: {
'Content-Type': 'application/json',
},
body: xrd1,
},
};
MockRucioServerFactory.createMockRucioServer(true, [listRSEsEndpoint, getXRD1Endpoint]);

const res = MockHttpStreamableResponseFactory.getMockResponse();

const controller = appContainer.get<BaseController<ListRSEsControllerParameters, ListRSEsRequest>>(CONTROLLERS.LIST_RSES);
const controllerParams: ListRSEsControllerParameters = {
rucioAuthToken: MockRucioServerFactory.VALID_RUCIO_TOKEN,
response: res as unknown as NextApiResponse,
rseExpression: 'XRD1',
rseExpression: '*',
};

await controller.execute(controllerParams);
Expand All @@ -136,8 +199,9 @@ describe('List RSEs Feature tests', () => {

await done;

expect(receivedData.length).toEqual(1);
expect(receivedData.length).toEqual(2);
expect(receivedData[0].id).toEqual('464cd7656db842c78261bcc2a087bbcb');
expect(receivedData[0].rse_type).toEqual(RSEType.DISK);
expect(receivedData[1].status).toEqual('error');
});
});

0 comments on commit 9c1513f

Please sign in to comment.