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

deps: update interface-datastore and friends #409

Merged
merged 5 commits into from
Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/js-test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
os: [ubuntu-latest, macos-latest]
node: [16]
fail-fast: true
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ logs
*.log

coverage
.coverage

# Runtime data
pids
Expand Down
16 changes: 8 additions & 8 deletions packages/ipfs-repo-migrations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@
"dependencies": {
"@ipld/dag-pb": "^2.1.0",
"cborg": "^1.3.4",
"datastore-core": "^7.0.0",
"datastore-core": "^8.0.1",
"debug": "^4.1.0",
"fnv1a": "^1.0.1",
"interface-blockstore": "^2.0.2",
"interface-datastore": "^6.0.2",
"interface-blockstore": "^3.0.0",
"interface-datastore": "^7.0.0",
"it-length": "^1.0.1",
"multiaddr": "^10.0.1",
"multiformats": "^9.0.4",
Expand All @@ -192,11 +192,11 @@
"@types/varint": "^6.0.0",
"aegir": "^37.5.0",
"aws-sdk": "^2.884.0",
"blockstore-core": "^1.0.2",
"blockstore-datastore-adapter": "^2.0.1",
"datastore-fs": "^7.0.0",
"datastore-level": "^8.0.0",
"datastore-s3": "^9.0.0",
"blockstore-core": "^2.0.0",
"blockstore-datastore-adapter": "^3.0.1",
"datastore-fs": "^8.0.0",
"datastore-level": "^9.0.0",
"datastore-s3": "^10.0.0",
"protobufjs-cli": "^1.0.0",
"just-safe-set": "^4.1.1",
"level-5": "npm:level@^5.0.0",
Expand Down
25 changes: 17 additions & 8 deletions packages/ipfs-repo-migrations/test/fixtures/repo.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@

import loadFixture from 'aegir/fixtures'
import { CONFIG_KEY, VERSION_KEY } from '../../src/utils.js'
import fs from 'fs/promises'

/**
* @typedef {import('../../src/types').Backends} Backends
* @typedef {import('../types').SetupOptions} SetupOptions
* @typedef {import('../types').CreateBackends} CreateBackends
*/

/**
*
* @param {(dir: string) => import('../../src/types').Backends} createBackends
* @param {*} prefix
* @returns
* @param {CreateBackends} createBackends
* @param {SetupOptions} [opts]
*/
export async function createRepo (createBackends, prefix) {
const dir = `${prefix ? `${prefix}/` : ''}test-repo-for-${Date.now()}`
const backends = createBackends(dir)
export async function createRepo (createBackends, opts = {}) {
let dir = opts.dir
const prefix = opts.prefix ?? ''

if (dir == null) {
dir = [prefix, `test-repo-for-${Date.now()}`].filter(Boolean).join('/')
await fs.mkdir(dir, {
recursive: true
})
}

const backends = createBackends(dir, opts.createBackends)
await backends.root.open()
await backends.root.close()

return {
dir,
prefix,
backends
}
}
Expand Down
196 changes: 126 additions & 70 deletions packages/ipfs-repo-migrations/test/migrations/migration-10-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,128 +53,184 @@ async function validate (store) {
if (store instanceof BaseBlockstore) {
const key = CID.parse(`b${name.toLowerCase()}`)

expect(await store.has(key)).to.be.true(`Could not read key ${name}`)
expect(equals(await store.get(key), keys[name])).to.be.true(`Could not read value for key ${keys[name]}`)
await expect(store.has(key)).to.eventually.be.true(`Could not read key ${name} from blockstore`)
expect(equals(await store.get(key), keys[name])).to.be.true(`Could not read value for key ${keys[name]} from blockstore`)
} else {
const key = new Key(`/${name}`)

await expect(store.has(key)).to.eventually.be.true(`Could not read key ${name}`)
expect(equals(await store.get(key), keys[name])).to.be.true(`Could not read value for key ${keys[name]}`)
await expect(store.has(key)).to.eventually.be.true(`Could not read key ${name} from datastore`)
expect(equals(await store.get(key), keys[name])).to.be.true(`Could not read value for key ${keys[name]} from datastore`)
}
}

await store.close()
}

/**
* @param {Backends} backends
* @param {*} LevelImpl
* @returns {Backends}
*/
function withLevels (backends, LevelImpl) {
const output = {
...backends
}

Object.entries(backends)
.forEach(([key, value]) => {
// @ts-ignore it's ok
output[key] = withLevel(value, LevelImpl)
})

return output
}

/**
* @param {Datastore} store
* @param {*} LevelImpl
*/
function withLevel (store, LevelImpl) {
let parent = {
child: store
}

while (parent.child) {
if (parent.child.constructor.name === 'LevelDatastore') {
// @ts-ignore undocumented properties
parent.child.database = LevelImpl
// @ts-ignore undocumented properties
delete parent.child.db

return store
}

// @ts-ignore undocumented properties
parent = parent.child
}

return store
}

/**
* @param {import('../types').SetupFunction} setup
* @param {import('../types').CleanupFunction} cleanup
*/
export function test (setup, cleanup) {
describe('migration 10', function () {
this.timeout(1024 * 1000)
/** @type {string} */
let dir
/** @type {import('../../src/types').Backends} */
let backends

beforeEach(async () => {
({ dir, backends } = await setup())
})

afterEach(async () => {
await cleanup(dir)
})

describe('forwards', () => {
/** @type {string} */
let dir
/** @type {import('../../src/types').Backends} */
let backends
/** @type {string} */
let prefix

beforeEach(async () => {
({ dir, prefix, backends } = await setup({
createBackends: {
createLevel: (path) => new Level5(path, {
valueEncoding: 'binary'
})
}
}))

for (const backend of Object.values(backends)) {
await bootstrap(withLevel(backend, Level5))
await bootstrap(backend)
}
})

afterEach(async () => {
if (dir != null) {
await cleanup(dir)
}
})

it('should migrate keys and values forward', async () => {
await migration.migrate(withLevels(backends, Level6), () => {})
({ backends } = await setup({
dir,
prefix,
createBackends: {
createLevel: (path) => new Level6(path, {
valueEncoding: 'binary'
})
}
}))

await migration.migrate(backends, () => {})

for (const backend of Object.values(backends)) {
await validate(withLevel(backend, Level6))
await validate(backend)
}
})
})

describe('backwards using level@6.x.x', () => {
/** @type {string} */
let dir
/** @type {import('../../src/types').Backends} */
let backends
/** @type {string} */
let prefix

beforeEach(async () => {
({ dir, prefix, backends } = await setup({
createBackends: {
createLevel: (path) => new Level6(path, {
valueEncoding: 'binary'
})
}
}))

for (const backend of Object.values(backends)) {
await bootstrap(withLevel(backend, Level6))
await bootstrap(backend)
}
})

afterEach(async () => {
if (dir != null) {
await cleanup(dir)
}
})

it('should migrate keys and values backward', async () => {
await migration.revert(withLevels(backends, Level6), () => {})
({ backends } = await setup({
dir,
prefix,
createBackends: {
createLevel: (path) => new Level6(path, {
valueEncoding: 'binary'
})
}
}))

await migration.revert(backends, () => {})

;({ backends } = await setup({
dir,
prefix,
createBackends: {
createLevel: (path) => new Level5(path, {
valueEncoding: 'binary'
})
}
}))

for (const backend of Object.values(backends)) {
await validate(withLevel(backend, Level5))
await validate(backend)
}
})
})

describe('backwards using level@5.x.x', () => {
/** @type {string} */
let dir
/** @type {import('../../src/types').Backends} */
let backends
/** @type {string} */
let prefix

beforeEach(async () => {
({ dir, prefix, backends } = await setup({
createBackends: {
createLevel: (path) => new Level6(path, {
valueEncoding: 'binary'
})
}
}))

for (const backend of Object.values(backends)) {
await bootstrap(withLevel(backend, Level6))
await bootstrap(backend)
}
})

afterEach(async () => {
if (dir != null) {
await cleanup(dir)
}
})

it('should migrate keys and values backward', async () => {
await migration.revert(withLevels(backends, Level5), () => {})
({ backends } = await setup({
dir,
prefix,
createBackends: {
createLevel: (path) => new Level5(path, {
valueEncoding: 'binary'
})
}
}))

await migration.revert(backends, () => {})

;({ backends } = await setup({
dir,
prefix,
createBackends: {
createLevel: (path) => new Level5(path, {
valueEncoding: 'binary'
})
}
}))

for (const backend of Object.values(backends)) {
await validate(withLevel(backend, Level5))
await validate(backend)
}
})
})
Expand Down
Loading