Skip to content
Open
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
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,15 @@ class CouchContinuum {
}).then(({ jobs }) => {
return { jobs: jobs || [] }
})
let isInUse = false
const re = new RegExp(`/${dbName}/`)
for (const { database, source, target } of [...jobs, ...activeTasks]) {
const re = new RegExp(`/${dbName}/`)
if (database) {
assert.strictEqual(re.test(database), true)
if (re.test(database) || re.test(source) || re.test(target)) {
isInUse = true
}
assert.strictEqual(re.test(source), true)
assert.strictEqual(re.test(target), true)
}
if (isInUse) {
throw new Error(`Database ${dbName} is still in use.`)
}
} catch (error) {
if (error.error === 'illegal_database_name') {
Expand Down
75 changes: 48 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"devDependencies": {
"dependency-check": "^4.1.0",
"mocha": "^8.0.1",
"mocha": "^8.1.1",
"standard": "^14.3.4"
},
"repository": {
Expand Down
26 changes: 24 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,34 @@ describe([name, version].join(' @ '), function () {
})
})

it('should check for databases in use', function () {
it('should check for databases in use', async function () {
assert.rejects(this.continuum._isInUse(dbName))
await request({
method: 'POST',
url: `${this.continuum.url.href}_replicate`,
json: {
cancel: true,
continuous: true,
source: this.continuum.source.href,
target: this.continuum.target.href
}
})
assert.doesNotReject(this.continuum._isInUse(dbName))
})

after(async function () {
await this.promise
try {
await request({
method: 'POST',
url: `${this.continuum.url.href}_replicate`,
json: {
cancel: true,
continuous: true,
source: this.continuum.source.href,
target: this.continuum.target.href
}
})
} catch {}
})
})
})