-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(verdaccio-memory): race condition on save a package (#365)
* fix(verdaccio-memory): race condition on save a package * chore: reable node 8 * add new tests
- Loading branch information
1 parent
4a1fb42
commit 70c1fb1
Showing
6 changed files
with
338 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Package } from '@verdaccio/types'; | ||
|
||
export function stringifyPackage(pkg: Package) { | ||
return JSON.stringify(pkg, null, '\t'); | ||
} | ||
|
||
export function parsePackage(pkg: string) { | ||
return JSON.parse(pkg); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { Logger, IPluginStorage, IPackageStorage } from '@verdaccio/types'; | ||
import { VerdaccioError } from '@verdaccio/commons-api'; | ||
|
||
import { ConfigMemory } from '../src/local-memory'; | ||
import { DataHandler } from '../src/memory-handler'; | ||
import LocalMemory from '../src/index'; | ||
|
||
import config from './partials/config'; | ||
|
||
const logger: Logger = { | ||
error: e => console.warn(e), | ||
info: e => console.warn(e), | ||
debug: e => console.warn(e), | ||
child: e => console.warn(e), | ||
warn: e => console.warn(e), | ||
http: e => console.warn(e), | ||
trace: e => console.warn(e), | ||
}; | ||
|
||
const defaultConfig = { logger, config: null }; | ||
|
||
describe('memory unit test .', () => { | ||
describe('LocalMemory', () => { | ||
test('should create an LocalMemory instance', () => { | ||
const localMemory: IPluginStorage<ConfigMemory> = new LocalMemory(config, defaultConfig); | ||
|
||
expect(localMemory).toBeDefined(); | ||
}); | ||
|
||
test('should create add a package', done => { | ||
const localMemory: IPluginStorage<ConfigMemory> = new LocalMemory(config, defaultConfig); | ||
localMemory.add('test', (err: VerdaccioError) => { | ||
expect(err).toBeNull(); | ||
localMemory.get((err: VerdaccioError, data: DataHandler) => { | ||
expect(err).toBeNull(); | ||
expect(data).toHaveLength(1); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
test('should reach max limit', done => { | ||
config.limit = 2; | ||
const localMemory: IPluginStorage<ConfigMemory> = new LocalMemory(config, defaultConfig); | ||
|
||
localMemory.add('test1', err => { | ||
expect(err).toBeNull(); | ||
localMemory.add('test2', err => { | ||
expect(err).toBeNull(); | ||
localMemory.add('test3', err => { | ||
expect(err).not.toBeNull(); | ||
expect(err.message).toMatch(/Storage memory has reached limit of limit packages/); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
test('should remove a package', done => { | ||
const pkgName = 'test'; | ||
const localMemory: IPluginStorage<ConfigMemory> = new LocalMemory(config, defaultConfig); | ||
localMemory.add(pkgName, err => { | ||
expect(err).toBeNull(); | ||
localMemory.remove(pkgName, err => { | ||
expect(err).toBeNull(); | ||
localMemory.get((err, data) => { | ||
expect(err).toBeNull(); | ||
expect(data).toHaveLength(0); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.