Make another file including broken lines

This commit is contained in:
porink0424
2024-04-10 15:34:02 +09:00
parent b0d432e806
commit c1a86d0efd
2 changed files with 11 additions and 4 deletions
+3 -2
View File
@@ -87,12 +87,13 @@ if __name__ == "__main__":
]:
create_optuna_storage(storage)
# Add a broken line to the random position in the journal.log to test error handling
# Make a file including a broken line to the random position to test error handling
shutil.copyfile(os.path.join(BASE_DIR, "journal.log"), os.path.join(BASE_DIR, "journal-broken.log"))
broken_line = (
'{"op_code": ..., "worker_id": "0000", "study_id": 0,'
'"datetime_start": "2024-04-01T12:00:00.000000"}\n'
)
with open(os.path.join(BASE_DIR, "journal.log"), "r+") as f:
with open(os.path.join(BASE_DIR, "journal-broken.log"), "r+") as f:
lines = f.readlines()
lines.insert(random.randint(0, len(lines)), broken_line)
f.truncate(0)
+8 -2
View File
@@ -15,7 +15,6 @@ describe("Test Journal File Storage", async () => {
const studies = await Promise.all(
studySummaries.map((_summary, index) => storage.getStudy(index))
)
const errors = storage.getErrors()
it("Check the study including Infinities", () => {
const study = studies.find((s) => s.study_name === "single-inf")
@@ -38,7 +37,14 @@ describe("Test Journal File Storage", async () => {
}
})
it("Check the parsing errors", () => {
it("Check the parsing errors", async () => {
const blob = await openAsBlob(
path.resolve(".", "test", "asset", "journal-broken.log")
)
const buf = await blob.arrayBuffer()
const storage = new mut.JournalFileStorage(buf)
const errors = storage.getErrors()
assert.strictEqual(errors.length, 1)
assert.strictEqual(
errors[0].message,