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

log-server: tweak Store API, add SQLiteStore tests #174

Merged
merged 10 commits into from
Jul 31, 2023
5 changes: 5 additions & 0 deletions .changeset/curvy-cycles-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lightmill/log-server': major
---

Rename Store#addRunLogs to Store#addLogs.
5 changes: 5 additions & 0 deletions .changeset/shaggy-dancers-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lightmill/log-server': major
---

Stop sorting logs per type with SQLiteStore#getLogs. Creation date is more relevant. Also update the corresponding database index.
5 changes: 5 additions & 0 deletions .changeset/thin-snakes-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lightmill/log-server': major
---

Store#addLogs now requires a createdAt property for each log
13 changes: 8 additions & 5 deletions packages/log-server/__tests__/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function MockStore(): MockStore {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
setRunStatus: vi.fn((...args) => Promise.resolve()),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
addRunLogs: vi.fn((...args) => Promise.resolve()),
addLogs: vi.fn((...args) => Promise.resolve()),
getLogValueNames: vi.fn(() =>
Promise.resolve(['mock-col1', 'mock-col2', 'mock-col3']),
),
Expand Down Expand Up @@ -378,7 +378,7 @@ describe('/experiments/runs/logs', () => {
describe('post /experiments/:experiment/runs/:run/logs', () => {
beforeEach(async () => {
vi.useFakeTimers({ toFake: ['Date'] });
vi.setSystemTime(1234567890);
vi.setSystemTime(100100);
store = MockStore();
let app = createLogServer({
store,
Expand Down Expand Up @@ -412,7 +412,7 @@ describe('/experiments/runs/logs', () => {
message:
'Client does not have permission to add logs to run "not-my-run" of experiment "test-exp"',
});
expect(store.addRunLogs).not.toHaveBeenCalled();
expect(store.addLogs).not.toHaveBeenCalled();
});

it('should add a single log to the run', async () => {
Expand All @@ -427,11 +427,12 @@ describe('/experiments/runs/logs', () => {
},
} satisfies PostLogsBody)
.expect(201, { status: 'ok' });
expect(store.addRunLogs).toHaveBeenCalledWith('test-exp', 'test-run', [
expect(store.addLogs).toHaveBeenCalledWith('test-exp', 'test-run', [
{
type: 'test-log',
values: { p1: 'v1', p2: 'v2' },
date,
createdAt: vi.getMockedSystemTime(),
},
]);
});
Expand All @@ -455,16 +456,18 @@ describe('/experiments/runs/logs', () => {
],
} satisfies PostLogsBody)
.expect(201, { status: 'ok' });
expect(store.addRunLogs).toHaveBeenCalledWith('test-exp', 'test-run', [
expect(store.addLogs).toHaveBeenCalledWith('test-exp', 'test-run', [
{
type: 'test-log',
values: { p1: 'v1', p2: 'v2' },
date: date1,
createdAt: vi.getMockedSystemTime(),
},
{
type: 'test-log',
values: { p3: 'v3', p4: 'v4' },
date: date2,
createdAt: vi.getMockedSystemTime(),
},
]);
});
Expand Down
Loading