Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("should generate a token", function() {
// Reinit mockMQTTClientObject
mockMQTTClientObject.reInitCommandCalled();
mockMQTTClientObject.resetPublishedMessage();
// Faking timer
var clock = sinon.useFakeTimers();
// Faking callback
var fakeCallback = sinon.spy();
// Init thingShadowClient
var thingShadows = thingShadow( {
keyPath:'test/data/private.pem.key',
certPath:'test/data/certificate.pem.crt',
caPath:'test/data/root-CA.crt',
clientId:'dummy-client-1',
host:'XXXX.iot.us-east-1.amazonaws.com'
}, {
operationTimeout:1000 // Set operation timeout to be 1 sec
} );
// Register callback
thingShadows.on('timeout', fakeCallback);
// Register a thing
thingShadows.register('testShadow3');
it('should provide minimum throughput', () => {
let initialDate = new Date(2011, 9, 1).getTime();
let clock = sinon.useFakeTimers(initialDate);
let sampler = new GuaranteedThroughputSampler(2, 0);
clock = sinon.useFakeTimers(initialDate + 20000);
let expectedTags = { 'sampler.type': 'lowerbound', 'sampler.param': 0 };
[true, true, false].forEach(expectedDecision => {
let actualTags = {};
let decision = sampler.isSampled('testOperationName', actualTags);
// We asked for 2 traces per second and 0% probability for the rest.
// Since the test runs under one second, we expect 2 successful samples
// and one unsuccessful.
if (expectedDecision) {
assert.isTrue(decision, 'must sample');
assert.deepEqual(expectedTags, actualTags);
} else {
assert.isFalse(decision, 'must not sample');
assert.deepEqual({}, actualTags);
it('update balance', () => {
let initialDate = new Date(2011, 9, 1).getTime();
let clock = sinon.useFakeTimers(initialDate);
let limiter = new RateLimiter(0.1, 1);
assert.equal(
true,
limiter._balance <= 1 && limiter._balance >= 0,
'balance should be initialized to a random value between [0:1]'
);
limiter._balance = 1.0;
assert.equal(limiter.checkCredit(1), true, 'expected checkCredit to be true');
limiter.update(0.1, 3);
clock.restore();
// move time 20s forward, enough to accumulate credits for 2 messages
clock = sinon.useFakeTimers(initialDate + 20000);
assert.equal(limiter.checkCredit(1), true, 'expected checkCredit to be true');
assert.equal(limiter.checkCredit(1), true, 'expected checkCredit to be true');
assert.equal(limiter.checkCredit(1), false, 'expected checkCredit to be false');
// move time 30s forward, enough to accumulate credits for another message (should have
// enough credits for 3 at this point)
clock = sinon.useFakeTimers(initialDate + 50000);
assert.equal(limiter.checkCredit(1), true, 'expected checkCredit to be true');
assert.equal(limiter._balance, 2, 'balance should be at 2 after spending 1');
// move time 5s forward, not enough to accumulate credits for another message
clock = sinon.useFakeTimers(initialDate + 55000);
// reduce the maxBalance so the limiter is capped at 1
limiter.update(0.1, 1);
assert.equal(limiter._balance, 2.5 / 3.0, 'balance should be proportional to the original range');
assert.equal(limiter.checkCredit(1), false, 'expected checkCredit to be false');
it('should be able to dispatch actions from the other module', () => {
const asyncTimeToDelay = 2000
const timer = Sinon.useFakeTimers()
@Module('Foo')
class FooModule extends Ayanami<{ foo: string }> {
defaultState = {
foo: '1',
}
@Reducer()
set(state: { foo: string }, payload: string) {
return { ...state, foo: payload }
}
}
@Module('Bar')
class BarModule extends Ayanami<{}> {
defaultState = {}
beforeEach(() => {
clock = sinon.useFakeTimers();
});
beforeEach(function () {
this.clock = sinon.useFakeTimers();
reconstruct_fake_publish_engine();
});
global.window = {
addEventListener: sinon.stub(),
parent: {
postMessage: sinon.stub()
}
};
global.document = {
addEventListener: sinon.stub(),
body: {
scrollHeight: 100
}
};
client = new Client({syncLang: false, syncTitle: false});
sendEvent = sinon.stub(client, 'sendEvent');
sendMessage = sinon.stub(client, '_sendMessage');
clock = sinon.useFakeTimers();
});
before(() => clock = sinon.useFakeTimers());
after(() => clock.restore());
beforeEach(function () {
clock = sinon.useFakeTimers();
});
beforeEach(function () {
shipit = createShipitInstance();
clock = sinon.useFakeTimers(1397730698075);
});
afterEach(function () {