Skip to content

Commit

Permalink
Make another file including broken lines
Browse files Browse the repository at this point in the history
  • Loading branch information
porink0424 committed Apr 10, 2024
1 parent b0d432e commit c1a86d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions tslib/storage/test/generate_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ def objective_single_nan_report(trial: optuna.Trial) -> float:
]:
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)
Expand Down
10 changes: 8 additions & 2 deletions tslib/storage/test/journal.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand Down

0 comments on commit c1a86d0

Please sign in to comment.