Skip to content

Commit

Permalink
new test: citizens can access supervisor's cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Akamaozu committed Nov 23, 2017
1 parent b481731 commit 16cf7c3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/citizen/cache-accesser.js
@@ -0,0 +1,9 @@
var supe = require('../../index');

supe.noticeboard.watch( 'sample-notice', 'send-reply-mail', reply_via_mail, { useCache: true });

function reply_via_mail( msg ){
supe.mail.send({ notice: 'sample-notice', received: msg.notice });
}

setTimeout( process.exit, 10000 );
37 changes: 37 additions & 0 deletions test/test.js
Expand Up @@ -837,5 +837,42 @@ describe('Supe Test Suite', function(){

supervisor.start( 'notice-sender', './test/citizen/notice-sender', { retries: 0 });
});

it('can use supervisor\'s noticeboard cache', function( done ){

this.timeout( 5000 );

var payload_to_cache = { success: true };

// handle citizen's response to cache test
supervisor.noticeboard.watch( 'supervisor-message', 'assess-cache-access', access_cache_access );

// cache payload
supervisor.noticeboard.notify( 'sample-notice', payload_to_cache );

supervisor.start( 'cache-accesser', './test/citizen/cache-accesser' );

function access_cache_access( msg ){

var envelope = msg.notice;

if( envelope.type !== 'mail' ) return;
if( envelope.from !== 'cache-accesser' ) return;

var response = envelope.msg.received,
payload_matches_cache = true;

for( var key in payload_to_cache ){
if( ! payload_to_cache.hasOwnProperty( key ) ) continue;

if( ! response.hasOwnProperty( key ) ) payload_matches_cache = false;
if( payload_to_cache[ key ] != response[ key ] ) payload_matches_cache = false;

break;
}

if( payload_matches_cache ) done();
}
});
});
});

0 comments on commit 16cf7c3

Please sign in to comment.