Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <gerwitzm@lovullo.com>2017-02-13 14:51:04 -0500
committerMike Gerwitz <gerwitzm@lovullo.com>2017-02-13 15:07:26 -0500
commit3b1df602e18effb66b604c16ace7756c30b2462f (patch)
treef4bb65d0cdff9836a2f9d3a2f713d4b60b674f4a
parente610372c8443ba5c5e73ed0791e642d82772d5cd (diff)
downloadliza-3b1df602e18effb66b604c16ace7756c30b2462f.tar.gz
liza-3b1df602e18effb66b604c16ace7756c30b2462f.tar.bz2
liza-3b1df602e18effb66b604c16ace7756c30b2462f.zip
DataValidator: Always clear store state
In practice, not clearing the store and allowing it to use previous state has the effect of instantly "fixing" failures if there happens to be more than one validation call. This was a log of debugging for a one-line change. * src/validate/DataValidator.js (_populateStore): Always clear store. * test/validate/DataValidatorTest.js: Add test. DEV-2299
-rw-r--r--src/validate/DataValidator.js3
-rw-r--r--test/validate/DataValidatorTest.js39
2 files changed, 41 insertions, 1 deletions
diff --git a/src/validate/DataValidator.js b/src/validate/DataValidator.js
index 12e663f..3690ac5 100644
--- a/src/validate/DataValidator.js
+++ b/src/validate/DataValidator.js
@@ -193,7 +193,8 @@ module.exports = Class( 'DataValidator',
{
if ( data === undefined )
{
- return Promise.resolve( [] );
+ // it's important that we don't re-use previous state
+ return store.clear().then( [] );
}
const mapf = ( subkey !== undefined )
diff --git a/test/validate/DataValidatorTest.js b/test/validate/DataValidatorTest.js
index b31a93e..e2364d3 100644
--- a/test/validate/DataValidatorTest.js
+++ b/test/validate/DataValidatorTest.js
@@ -212,6 +212,45 @@ describe( 'DataValidator', () =>
.validate( {} )
).to.eventually.be.rejectedWith( expected_e );
} );
+
+
+ [
+ [],
+ [ {} ],
+ [ undefined ],
+ [ undefined, {} ],
+ [ undefined, undefined ],
+ [ {}, undefined ],
+ ].forEach( args => it( 'does not re-use previous store state', () =>
+ {
+ const bvalidator = createMockBucketValidator();
+ const vmonitor = ValidStateMonitor();
+ const dep_factory = createMockDependencyFactory();
+
+ const stores = {
+ store: MemoryStore(),
+ bstore: sinon.createStubInstance( MemoryStore ),
+ cstore: sinon.createStubInstance( MemoryStore ),
+ };
+
+ const { bstore, cstore } = stores;
+
+ const cleared = which =>
+ {
+ cleared[ which ] = true;
+ return Promise.resolve();
+ };
+
+ bstore.clear = () => cleared( 'b' );
+ cstore.clear = () => cleared( 'c' );
+
+ const sut = Sut( bvalidator, vmonitor, dep_factory, () => stores );
+
+ return sut.validate.apply( sut, args )
+ .then( () =>
+ expect( cleared.b && cleared.c ).to.be.true
+ );
+ } ) );
} );