Skip to content
Snippets Groups Projects
Commit cd164c67 authored by Xiao Gui's avatar Xiao Gui
Browse files

bugfix: retries on failed saneUrl set

parent 71aa39f1
No related branches found
No related tags found
No related merge requests found
......@@ -43,6 +43,7 @@ class Store {
async getToken() {
this.token = await this.wrapper.getScopedToken({ projectId: OBJ_STORAGE_PROJECT_ID })
return this.token
}
get(id) {
......@@ -60,7 +61,7 @@ class Store {
})
}
set(id, value) {
_set(id, value) {
return new Promise((rs, rj) => {
request.put(`${this.objStorateRootUrl}/${id}`, {
headers: {
......@@ -75,6 +76,17 @@ class Store {
})
}
async set(id, value) {
try {
const result = await this._set(id, value)
return result
} catch (e) {
await this.getToken()
const result = await this._set(id, value)
return result
}
}
async healthCheck(){
}
......
......@@ -28,6 +28,10 @@ describe('> store.js', () => {
expect(token).to.equal(fakeToken)
})
it('> spy gets reset', async () => {
expect(getTokenSpy.notCalled).to.be.true
})
it('> get works', async () => {
const scope = nock(objStorateRootUrl)
.get(`/${objName}`)
......@@ -50,8 +54,22 @@ describe('> store.js', () => {
})
await store.set(objName, objContent)
expect(scope.isDone()).to.be.true
})
it('> set retries if at first fails', async () => {
let index = 0
const scope = nock(objStorateRootUrl)
.put(`/${objName}`)
.twice()
.reply((_uri, _reqBody, cb) => {
cb(null, [ index % 2 === 0 ? 401 : 200 ])
index ++
})
await store.set(objName, objContent)
expect(scope.isDone()).to.be.true
expect(getTokenSpy.called).to.be.true
})
})
})
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment