Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions resources/pinba.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,79 +12,79 @@
"type": "string",
"id": 1
},
"serverName": {
"server_name": {
"rule": "required",
"type": "string",
"id": 2
},
"scriptName": {
"script_name": {
"rule": "required",
"type": "string",
"id": 3
},
"requestCount": {
"request_count": {
"rule": "required",
"type": "uint32",
"id": 4
},
"documentSize": {
"document_size": {
"rule": "required",
"type": "uint32",
"id": 5
},
"memoryPeak": {
"memory_peak": {
"rule": "required",
"type": "uint32",
"id": 6
},
"requestTime": {
"request_time": {
"rule": "required",
"type": "float",
"id": 7
},
"ruUtime": {
"ru_utime": {
"rule": "required",
"type": "float",
"id": 8
},
"ruStime": {
"ru_stime": {
"rule": "required",
"type": "float",
"id": 9
},
"timerHitCount": {
"timer_hit_count": {
"rule": "repeated",
"type": "uint32",
"id": 10,
"options": {
"packed": false
}
},
"timerValue": {
"timer_value": {
"rule": "repeated",
"type": "float",
"id": 11,
"options": {
"packed": false
}
},
"timerTagCount": {
"timer_tag_count": {
"rule": "repeated",
"type": "uint32",
"id": 12,
"options": {
"packed": false
}
},
"timerTagName": {
"timer_tag_name": {
"rule": "repeated",
"type": "uint32",
"id": 13,
"options": {
"packed": false
}
},
"timerTagValue": {
"timer_tag_value": {
"rule": "repeated",
"type": "uint32",
"id": 14,
Expand All @@ -101,7 +101,7 @@
"type": "uint32",
"id": 16
},
"memoryFootprint": {
"memory_footprint": {
"type": "uint32",
"id": 17
},
Expand All @@ -114,15 +114,15 @@
"type": "string",
"id": 19
},
"tagName": {
"tag_name": {
"rule": "repeated",
"type": "uint32",
"id": 20,
"options": {
"packed": false
}
},
"tagValue": {
"tag_value": {
"rule": "repeated",
"type": "uint32",
"id": 21,
Expand Down
45 changes: 45 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,51 @@ describe('Pinba', function () {
done();
});
});

it('flush() must verify message before sending', function () {
var validData = {
hostname: 'hostname',
server_name: 'server_name',
script_name: 'script_name',
schema: 'schema'
};
var socket_create_stub = sinon.stub(require('dgram'), "createSocket");
socket_create_stub.returns({
on: noop,
send: noop
});

try {
checkMessageVerification(validData, null);
checkMessageVerification(Object.assign({}, validData, {hostname: 42}), 'hostname');
checkMessageVerification(Object.assign({}, validData, {server_name: 42}), 'server_name');
checkMessageVerification(Object.assign({}, validData, {script_name: 42}), 'script_name');
checkMessageVerification(Object.assign({}, validData, {schema: 42}), 'schema');
} finally {
socket_create_stub.restore();
}

function checkMessageVerification(data, invalidFieldName) {
var error = null;

try {
(new Pinba.Request(data)).flush();
} catch (err) {
error = err;
} finally {
if (invalidFieldName) {
assert.ok(error instanceof Error,
'Verification error is missing');
assert.ok(error.message.indexOf(invalidFieldName + ':') === 0,
'Verification error message must refer on invalid field name');
} else {
assert.strictEqual(error, null, 'Got unexpected verification error');
}
}
}

function noop() {}
});
});
});
});