Skip to content

Commit 0729f9e

Browse files
committed
add large dataset upload test
1 parent 3280ff9 commit 0729f9e

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,8 @@
3737
"rimraf": "^3.0.2",
3838
"test-listen": "^1.1.0",
3939
"tmp": "^0.2.1"
40+
},
41+
"ava": {
42+
"timeout": "60s"
4043
}
4144
}

tests/upload-large-dataset.test.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
const test = require("ava")
2+
const getDB = require("../src/db")
3+
const app = require("../app")
4+
const micro = require("micro")
5+
const listen = require("test-listen")
6+
const postJSON = require("bent")("json", "POST")
7+
8+
test("Create session", async (t) => {
9+
const db = await getDB({ testDB: true })
10+
const service = micro(app)
11+
const url = await listen(service)
12+
13+
const udt = {
14+
interface: {
15+
type: "image_segmentation",
16+
availableLabels: ["valid", "invalid"],
17+
regionTypesAllowed: ["bounding-box", "polygon", "point"],
18+
},
19+
samples: [],
20+
}
21+
22+
const numSamples = 100000
23+
for (let i = 0; i < numSamples; i++) {
24+
udt.samples.push({
25+
imageUrl:
26+
"https://s3.amazonaws.com/asset.workaround.online/example-jobs/sticky-notes/image1.jpg",
27+
})
28+
}
29+
30+
const startPostJSONTime = Date.now()
31+
const response = await postJSON(`${url}/api/session`, {
32+
udt,
33+
})
34+
console.log(
35+
`Time to create ${numSamples} sample session: ${(
36+
(Date.now() - startPostJSONTime) /
37+
1000
38+
).toFixed(1)}s`
39+
)
40+
t.assert(response.short_id)
41+
const addedSession = db
42+
.prepare(
43+
`SELECT *
44+
FROM latest_session_state
45+
WHERE short_id = ?
46+
LIMIT 1`
47+
)
48+
.get(response.short_id)
49+
t.assert(addedSession)
50+
t.deepEqual(JSON.parse(addedSession.summary_object).interface, {
51+
type: "image_segmentation",
52+
availableLabels: ["valid", "invalid"],
53+
regionTypesAllowed: ["bounding-box", "polygon", "point"],
54+
})
55+
t.like(JSON.parse(addedSession.summary_object).summary.samples[0], {
56+
hasAnnotation: false,
57+
version: 0,
58+
})
59+
t.is(
60+
JSON.parse(addedSession.summary_object).summary.samples.length,
61+
numSamples
62+
)
63+
64+
db.destroy()
65+
})

0 commit comments

Comments
 (0)