Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test to open images and file information #222

Merged
merged 11 commits into from
Apr 14, 2021
103 changes: 103 additions & 0 deletions src/test/FILEINFO_CASA_VARIENTS.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { CARTA } from "carta-protobuf";

import { Client } from "./CLIENT";
import config from "./config.json";

let testServerUrl = config.serverURL;
let testSubdirectory = config.path.casa_varients;
let connectTimeout = config.timeout.connection;
let listFileTimeout = config.timeout.listFile;
let openFileTimeout = config.timeout.openFile;

interface AssertItem {
registerViewer: CARTA.IRegisterViewer;
fileInfoRequest: CARTA.IFileInfoRequest[];
precisionDigit?: number;
};

let assertItem: AssertItem = {
registerViewer: {
sessionId: 0,
clientFeatureFlags: 5,
},
precisionDigit: 4,
fileInfoRequest: [
{
file: "componentlist.image",
hdu: "",
},
{
file: "concatenated.image",
hdu: "",
},
{
file: "pVimage.image",
hdu: "",
},
{
file: "UVamp.image",
hdu: "",
},
{
file: "UVphase.image",
hdu: "",
},
],
};

describe("FILEINFO_CASA_VARIENTS: Testing if file info of a variant CASA images is correctly delivered by the backend", () => {

let Connection: Client;
beforeAll(async () => {
Connection = new Client(testServerUrl);
await Connection.open();
await Connection.registerViewer(assertItem.registerViewer);
}, connectTimeout);

describe(`Go to "${testSubdirectory}" folder`, () => {
let basePath: string;
beforeAll(async () => {
await Connection.send(CARTA.FileListRequest, { directory: "$BASE" });
basePath = (await Connection.receive(CARTA.FileListResponse) as CARTA.FileListResponse).directory;
}, listFileTimeout);
assertItem.fileInfoRequest.map(fileInfoRequest => {
describe(`query the info of file : ${fileInfoRequest.file}`, () => {
let FileInfoResponse: CARTA.FileInfoResponse;
test(`FILE_INFO_RESPONSE should arrive within ${openFileTimeout} ms".`, async () => {
await Connection.send(CARTA.FileInfoRequest, {
directory: `${basePath}/` + testSubdirectory,
...fileInfoRequest,
});
FileInfoResponse = await Connection.receive(CARTA.FileInfoResponse);
}, openFileTimeout);

test(`FILE_INFO_RESPONSE should match snapshot".`, async () => {
expect(FileInfoResponse).toMatchSnapshot({
fileInfo: {
// Date for creating a file is not a constant
date: expect.any(Object), // Might be a Number or Long
},
fileInfoExtended: {
"": {
// Skip this
headerEntries: expect.any(Object),
},
},
});
// Tolerance for precision digits
FileInfoResponse.fileInfoExtended[""].headerEntries.map(item => {
if (item["numericValue"]) {
expect(item).toMatchSnapshot({
numericValue: expect.any(Number),
});
expect(item["numericValue"].toExponential(assertItem.precisionDigit)).toMatchSnapshot();
}else{
expect(item).toMatchSnapshot();
}
});
});
});
});
});
afterAll(() => Connection.close());
});
184 changes: 184 additions & 0 deletions src/test/OPEN_IMAGE_CASA_VARIENTS.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
import { CARTA } from "carta-protobuf";
import { Client, IOpenFile } from "./CLIENT";
import config from "./config.json";
let testServerUrl: string = config.serverURL;
let testSubdirectory: string = config.path.casa_varients;
let connectTimeout: number = config.timeout.connection;
let openFileTimeout: number = config.timeout.openFile;
let readFileTimeout: number = config.timeout.readFile;
interface AssertItem {
registerViewer: CARTA.IRegisterViewer;
precisionDigit?: number;
filelist: CARTA.IFileListRequest;
fileOpen: CARTA.IOpenFile[];
setImageChannel: CARTA.ISetImageChannels[];
}
let assertItem: AssertItem = {
registerViewer: {
sessionId: 0,
apiKey: "",
clientFeatureFlags: 5,
},
precisionDigit: 4,
filelist: { directory: testSubdirectory },
fileOpen: [
{
directory: testSubdirectory,
file: "componentlist.image",
hdu: "",
fileId: 200,
renderMode: CARTA.RenderMode.RASTER,
},
{
directory: testSubdirectory,
file: "concatenated.image",
hdu: "",
fileId: 201,
renderMode: CARTA.RenderMode.RASTER,
},
{
directory: testSubdirectory,
file: "pVimage.image",
hdu: "",
fileId: 202,
renderMode: CARTA.RenderMode.RASTER,
},
{
directory: testSubdirectory,
file: "UVamp.image",
hdu: "",
fileId: 203,
renderMode: CARTA.RenderMode.RASTER,
},
{
directory: testSubdirectory,
file: "UVphase.image",
hdu: "",
fileId: 204,
renderMode: CARTA.RenderMode.RASTER,
},
],
setImageChannel: [
{
fileId: 200,
channel: 0,
stokes: 0,
requiredTiles: {
fileId: 200,
compressionType: CARTA.CompressionType.ZFP,
compressionQuality: 11,
tiles: [0],
},
},
{
fileId: 201,
channel: 0,
stokes: 0,
requiredTiles: {
fileId: 201,
compressionType: CARTA.CompressionType.ZFP,
compressionQuality: 11,
tiles: [0],
},
},
{
fileId: 202,
channel: 0,
stokes: 0,
requiredTiles: {
fileId: 202,
compressionType: CARTA.CompressionType.ZFP,
compressionQuality: 11,
tiles: [0],
},
},
{
fileId: 203,
channel: 0,
stokes: 0,
requiredTiles: {
fileId: 203,
compressionType: CARTA.CompressionType.ZFP,
compressionQuality: 11,
tiles: [0],
},
},
{
fileId: 204,
channel: 0,
stokes: 0,
requiredTiles: {
fileId: 204,
compressionType: CARTA.CompressionType.ZFP,
compressionQuality: 11,
tiles: [0],
},
},
],
}

describe("OPEN_IMAGE_CASA_VARIENTS: Testing the case of opening variant casa images", () => {
let Connection: Client;
beforeAll(async () => {
Connection = new Client(testServerUrl);
await Connection.open();
await Connection.registerViewer(assertItem.registerViewer);
}, connectTimeout);


describe(`Go to "${assertItem.filelist.directory}" folder`, () => {
beforeAll(async () => {
await Connection.send(CARTA.CloseFile, { fileId: -1 });
}, connectTimeout);

assertItem.fileOpen.map((fileOpen: CARTA.IOpenFile, index) => {

describe(`open/append the file "${fileOpen.file}"`, () => {
let ack: IOpenFile;
test(`OPEN_FILE_ACK and REGION_HISTOGRAM_DATA should arrive within ${openFileTimeout} ms`, async () => {
ack = await Connection.openFile(fileOpen);
}, openFileTimeout);

test(`OPEN_FILE_ACK should match snapshot`, () => {
let OpenFileAck: CARTA.IOpenFileAck = ack.OpenFileAck;
expect(OpenFileAck).toMatchSnapshot({
fileInfoExtended: {
headerEntries: expect.any(Object),
},
});
OpenFileAck.fileInfoExtended.headerEntries.map(item => {
if (item["numericValue"]) {
expect(item).toMatchSnapshot({
numericValue: expect.any(Number),
});
expect(item["numericValue"].toExponential(assertItem.precisionDigit)).toMatchSnapshot();
} else {
expect(item).toMatchSnapshot();
}
});
});

test(`REGION_HISTOGRAM_DATA should match snapshot`, () => {
expect(ack.RegionHistogramData).toMatchSnapshot({
histograms: expect.any(Object),
});
});
});

describe(`set image channel for the file "${fileOpen.file}"`, () => {
let RasterTileDataTemp: CARTA.RasterTileData;
test(`RASTER_TILE_DATA should arrive within ${readFileTimeout} ms`, async () => {
await Connection.send(CARTA.SetImageChannels, assertItem.setImageChannel[index]);
RasterTileDataTemp = await Connection.receive(CARTA.RasterTileData);
}, readFileTimeout);

test(`RASTER_TILE_DATA should match snapshot`, () => {
expect(RasterTileDataTemp).toMatchSnapshot();
});
});

});
});

afterAll(() => Connection.close());
});
Loading