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

Add all-id test #428

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/estate-id-create-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export async function main(argv: string[]) {
const idOutputQueue = async.queue<string>(async (id) => {
const {min_createat, max_createat, cnt} = idStats.get(id)!;
const {address, rawAddress} = idAttributes.get(id)!;
await out.write(`${id},${min_createat},${max_createat},${cnt},${address},${rawAddress}\n`);
await out.write(`${id},${min_createat},${max_createat},${cnt},"${address}","${rawAddress}"\n`);
idStats.delete(id);
idAttributes.delete(id);
}, 1)
Expand Down
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = {
"bin",
"__tests__",
"ipc.test.ts",
"addresses.test.ts"
"addresses.test.ts",
"all-ids.test.ts",
],
testEnvironment: "node"
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@
},
"scripts": {
"preinstall": "npx only-allow yarn",
"pretest": "docker rm -f prop-id-api__dynamodb-local &>/dev/null && sleep 1 && docker run -d -p 8000:8000 --rm --name prop-id-api__dynamodb-local amazon/dynamodb-local",
"pretest": "docker rm -f prop-id-api__dynamodb-local &>/dev/null && sleep 1 && docker run -d -p 8000:8000 --rm --name prop-id-api__dynamodb-local amazon/dynamodb-local -jar DynamoDBLocal.jar -inMemory -sharedDb",
"test": "jest",
"posttest": "docker stop prop-id-api__dynamodb-local || true",
"test:ipc": "jest ./src/__tests__/ipc.test.ts",
"test:all-ids": "yarn pretest && jest --testPathIgnorePatterns=\"bin __tests__\" -- ./src/all-ids.test.ts && yarn posttest",
"test:addresses": "node ./src/test_download-data.js && jest ./src/addresses.test.ts",
"lint": "eslint --ext .ts --ext .js src --cache",
"build": "tsc",
Expand Down
91 changes: 91 additions & 0 deletions src/all-ids.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import fs from 'fs'
import os from 'os'
import path from 'path'
import async from 'async'

import { DB } from './lib/dynamodb';

import { _handler } from './public';
import { APIGatewayProxyResult } from 'aws-lambda';
import { decorate, logger, authenticator } from './lib/decorators';

const handler = decorate(_handler, [logger, authenticator('id-req')]);


const allIds = fs.readFileSync(path.join(__dirname, '..', 'out', 'all-ids.csv'), {
encoding: 'utf-8',
}).split(/\n/).map((line) => line.trim().split(','));

beforeAll(async () => {
const queue = async.cargoQueue<Record<string, any>>(async (records) => {
// console.timeLog('loading IDs', `writing ${records.length} records...`);
const resp = await DB.batchWrite({
RequestItems: {
[process.env.AWS_DYNAMODB_ESTATE_ID_TABLE_NAME]: records.map((record) => ({
PutRequest: {
Item: record,
},
})),
}
}).promise();
const unprocessed = (resp.UnprocessedItems || {})[process.env.AWS_DYNAMODB_ESTATE_ID_TABLE_NAME] || [];
if (unprocessed.length > 0) {
console.error('unprocessed items', unprocessed);
throw new Error('unprocessed items');
}
}, 2, 25);
queue.error();

for (const row of allIds) {
const [id,_min_createat,_max_createat,_cnt,address,rawAddress] = row;
queue.push({
estateId: id,
address,
rawAddress,
zoom: 22,
serial: 1,
});
}
let progressTimer: NodeJS.Timeout | null = null;
(() => {
let lastLength = queue.length();
let lastTS = process.hrtime.bigint();
const logger = () => {
const length = queue.length();
if (length === 0) {
return;
}
let progress = lastLength - length;
const nowTS = process.hrtime.bigint();
const elapsed = nowTS - lastTS;
const perSecond = progress / Number(elapsed) * 1e9;
const timeRemaining = length / perSecond;
console.log(`queue length: ${length}, progress: ${progress} (${perSecond.toFixed(2)}/s, ${timeRemaining.toFixed(2)}s remaining)`);

lastLength = length;
lastTS = nowTS;
progressTimer = setTimeout(logger, 10_000);
};
logger();
})();
await queue.drain();
if (progressTimer) {
// clear the timeout so jest doesn't complain
clearTimeout(progressTimer);
}
}, 60_000 * 10); // give us 10 minutes to load the data

for (const row of allIds) {
test(`${row[0]} - ${row[5]} (ID発行)`, async () => {
const event = {
isDemoMode: true,
queryStringParameters: {
q: row[5],
},
};
// @ts-expect-error context and callback are not used
const lambdaResult = await handler(event) as APIGatewayProxyResult
const body = JSON.parse(lambdaResult.body)
expect(body[0].ID).toEqual(row[0]);
});
}
Loading