function testMutableLeak(mode) { const gpu = new GPU({ mode }); const kernel = gpu.createKernel(function() { return 1; }, { output: [1], pipeline: true }); kernel.build(); const cloneTextureSpy = sinon.spy(kernel.texture.constructor.prototype, 'beforeMutate'); const texture1 = kernel(); const texture2 = kernel(); assert.equal(cloneTextureSpy.callCount, 0); assert.equal(texture1.texture._refs, 1); assert.ok(texture1 === texture2); cloneTextureSpy.restore(); gpu.destroy(); }
assert.equal(newTextureSpy.callCount, 2); assert.equal(gpu.kernels.length, 2); newTextureSpy.restore(); gpu.destroy();
function testImmutableKernelTextureRecycling(precision, mode) { const gpu = new GPU({ mode }); const kernel = gpu.createKernel(function(v) { return v[0] + 1; }, { output: [1], pipeline: true, immutable: true, precision, }); let result = kernel([0]); const newTextureSpy = sinon.spy(kernel.texture.constructor.prototype, 'newTexture'); for (let i = 0; i < 10; i++) { let lastResult = result; result = kernel(result); lastResult.delete(); } assert.deepEqual(result.toArray(), new Float32Array([11])); assert.equal(newTextureSpy.callCount, 1); assert.equal(gpu.kernels.length, 2); newTextureSpy.restore(); gpu.destroy(); }
assert.equal(spy.callCount, 1); assert.ok(spy.calledWith(result.texture)); spy.restore(); done(); });
it('should NOT try to update any timestamp properties if `options.timestamps` option is disabled', function() { var instance = this.model.build({}); var propNames = this.model._getTimestampPropertyNames(); var getTimestampNamesSpy = sinon.spy(this.model, '_getTimestampPropertyNames'); instance._touchTimestamps(); instance.getData().should.not.have.property(propNames.createdAt); instance.getData().should.not.have.property(propNames.updatedAt); instance.getData().should.not.have.property(propNames.deletedAt); getTimestampNamesSpy.should.have.callCount(0); getTimestampNamesSpy.restore(); });
describe('helper/logger', function() { let spy = sinon.spy(console, 'log'); describe('.log()', function() { it('should print mesage', function() { logger.log("Test Message"); sinon.assert.calledWith(spy, sinon.match("Test Message")); spy.restore(); }); }); });
test('common-log trace method', (t) => { const cache = process.env.NODESHIFT_QUIET; process.env.NODESHIFT_QUIET = false; const spy = sinon.spy(console, 'log'); const { trace } = proxyquire('../lib/common-log', {})(); trace(); t.equal(spy.callCount, 1, 'should call console.log'); t.end(); // reset spy.restore(); process.env.NODESHIFT_QUIET = cache; });
it('$scope.rawtxListener() should be called when rawtx event received', function(){ socketio.removeListener('rawtx', scope.rawtxListener);//we remove the original method as it is bound undecorated to socketio var rawtxListener = sinon.spy(scope, 'rawtxListener');//we decorate the rawtxListener with a spy socketio.on('rawtx', rawtxListener);//we reattach the listener to the event socketio.emit('rawtx', {data: 'some strange data'}); socketio.emit('rawtx', {data: 'some strange data'}); sinon.assert.calledTwice(rawtxListener); sinon.assert.calledWith(rawtxListener, {data: 'some strange data'}); scope.mempoolEntry.size.should.be.equal(1002); rawtxListener.restore(); });
it('should NOT call the `getAndLock` method if the `lockTime` option is set AND the relevant document IS soft-deleted', function() { const getAndLockSpy = sinon.spy(this.model.storage, 'getAndLock'); return this.model.getByIdOrFail(this.doc.getKey(), {lockTime: 20}) .should.be.rejected.then(function() { getAndLockSpy.should.have.callCount(0); getAndLockSpy.restore(); }); });
it('handle result $auth + $end retry', function() { var authStub = sinon.stub(Schema.Client.prototype, 'auth'); var requestSpy = sinon.spy(Schema.Client.prototype, 'request'); serverRequestStub.onCall(0).callsArgWith(3, { $auth: true, $end: true, }); client.request('get', 'url', 'data'); assert.strictEqual(authStub.called, false); assert.strictEqual(requestSpy.calledTwice, true); authStub.restore(); requestSpy.restore(); });
test('handle fuctions not instrumented', function (t) { const stateSpy = sinon.spy(state, 'addEvent'); snapshotReader.setVulnerabiltiesMetadata(require('./fixtures/st/vulnerable_methods_invalid.json')); dbg.refreshInstrumentation(); t.assert('warning' in stateSpy.args[0][0], 'warning event was added to state'); t.equal(1, stateSpy.callCount, 'Add event was called once because of missing function from source'); stateSpy.restore(); t.end(); });
describe('Server generation without input file', () => { before(() => { generate.configure(options_object); }); it('An error is thrown', () => { const spy = sinon.spy(console, 'log'); generate.generateServer(null, cmd); spy.calledWith('You must select an input specification file!').should.equal(true); spy.restore(); }); });
it('should remove rawtx listener once $destroy event received on $scope', function(){ socketio.removeListener('rawtx', scope.rawtxListener); var rawtxListener = sinon.spy(scope, "rawtxListener"); socketio.on('rawtx', scope.rawtxListener); socketio.emit('rawtx', {data: 'test'}); sinon.assert.calledOnce(rawtxListener); scope.$emit('$destroy'); socketio.emit('rawtx', {data: 'test'}); sinon.assert.calledOnce(rawtxListener); rawtxListener.restore(); });
test('common-log info method', (t) => { const cache = process.env.NODESHIFT_QUIET; process.env.NODESHIFT_QUIET = false; const spy = sinon.spy(console, 'log'); const { info } = proxyquire('../lib/common-log', {})(); info(); t.equal(spy.callCount, 1, 'should call console.log'); t.end(); // reset spy.restore(); process.env.NODESHIFT_QUIET = cache; });
it('should NOT call the `getAndTouch` method if the `expiry` option is set AND the relevant document IS soft-deleted', function() { const getAndTouchSpy = sinon.spy(this.model.storage, 'getAndTouch'); return this.model.getByIdOrFail(this.doc.getKey(), {expiry: 1000}) .should.be.rejected.then(function() { getAndTouchSpy.should.have.callCount(0); getAndTouchSpy.restore(); }); });