Skip to content

Commit

Permalink
test(swing-store): Expect vat transcript archive files (currently fai…
Browse files Browse the repository at this point in the history
…ling)

Ref #10036
  • Loading branch information
gibson042 committed Sep 10, 2024
1 parent cb09170 commit 21ae513
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions packages/swing-store/test/deletion.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// @ts-check
import test from 'ava';
import path from 'path';

import { Buffer } from 'node:buffer';
import path from 'node:path';
import fs from 'node:fs';
import zlib from 'node:zlib';
import sqlite3 from 'better-sqlite3';
import { arrayIsLike } from '@agoric/internal/tools/ava-assertions.js';
import { tmpDir } from './util.js';
Expand Down Expand Up @@ -193,6 +195,7 @@ const setupTranscript = async (t, keepTranscripts) => {
return {
db,
dbDir,
archiveDir: '',
commit,
transcriptStore,
exportLog,
Expand All @@ -212,6 +215,7 @@ const execSlowTranscriptDeletion = async (t, { keepTranscripts }) => {
const {
db,
dbDir,
archiveDir,
commit,
transcriptStore,
exportLog,
Expand Down Expand Up @@ -241,12 +245,13 @@ const execSlowTranscriptDeletion = async (t, { keepTranscripts }) => {
'transcript.v1.4': t4,
'transcript.v1.6': t6,
};
const expectedArtifactNames = [
'transcript.v1.0.2',
'transcript.v1.2.4',
'transcript.v1.4.6',
'transcript.v1.6.8',
];
const expectedArtifactContents = {
'transcript.v1.0.2': 'aaa\nbbb\n',
'transcript.v1.2.4': 'ccc\nddd\n',
'transcript.v1.4.6': 'eee\nfff\n',
'transcript.v1.6.8': 'ggg\nhhh\n',
};
const expectedArtifactNames = Object.keys(expectedArtifactContents);

t.deepEqual(stripHashes(currentExportData), expectedLiveExportData);
t.is(
Expand All @@ -255,6 +260,17 @@ const execSlowTranscriptDeletion = async (t, { keepTranscripts }) => {
);
t.is(db.prepare('SELECT COUNT(*) FROM transcriptSpans').pluck().get(), 4);

// verify archived transcripts
t.deepEqual(
fs.readdirSync(archiveDir),
expectedArtifactNames.slice(0, -1).map(name => `${name}.gz`),
);
for (const name of expectedArtifactNames.slice(0, -1)) {
const filePath = path.join(archiveDir, `${name}.gz`);
const contents = zlib.gunzipSync(fs.readFileSync(filePath)).toString();
t.is(contents, expectedArtifactContents[name], `${filePath} contents`);
}

// an "operational"-mode export should list all spans, but only have
// artifacts for the current one
{
Expand Down Expand Up @@ -293,6 +309,15 @@ const execSlowTranscriptDeletion = async (t, { keepTranscripts }) => {
await commit();
t.deepEqual(exportLog, []);
}
t.deepEqual(
fs.readdirSync(archiveDir),
expectedArtifactNames.map(name => `${name}.gz`),
);
for (const name of expectedArtifactNames) {
const filePath = path.join(archiveDir, `${name}.gz`);
const contents = zlib.gunzipSync(fs.readFileSync(filePath)).toString();
t.is(contents, expectedArtifactContents[name], `${filePath} contents`);
}

// All exports (debug and non-debug) in this "terminated but not
// deleted" state will still have the export-data keys. Only
Expand Down

0 comments on commit 21ae513

Please sign in to comment.