update
This commit is contained in:
@@ -151,14 +151,14 @@ async function runTest() {
|
||||
// Small data (direct transport) - text, dictionary, arrowtable, jsontable, small image
|
||||
['chat_text', textData, 'text'],
|
||||
['chat_json', dictData, 'dictionary'],
|
||||
['arrow_table_small', arrowTableSmall, 'arrowtable'],
|
||||
// ['arrow_table_small', arrowTableSmall, 'arrowtable'],
|
||||
['json_table_small', jsonTableSmall, 'jsontable'],
|
||||
[filename_small_image, file_data_small_image, 'binary'],
|
||||
|
||||
// Large data (link transport) - large arrowtable, large jsontable, large image, large audio, large video, large binary
|
||||
// ['arrow_table_large', largeArrowTable, 'arrowtable'],
|
||||
['json_table_large', largeJsonTable, 'jsontable'],
|
||||
// [filename_large_image, file_data_large_image, 'binary'],
|
||||
[filename_large_image, file_data_large_image, 'binary'],
|
||||
// ['audio_clip_large', largeAudioData, 'audio'],
|
||||
// ['video_clip_large', largeVideoData, 'video'],
|
||||
// ['binary_file_large', largeBinaryData, 'binary']
|
||||
@@ -197,176 +197,6 @@ async function runTest() {
|
||||
console.log(`Sender: ${env.sender_name}`);
|
||||
console.log(`Payloads: ${env.payloads.length}\n`);
|
||||
|
||||
// Log transport type for each payload
|
||||
console.log('=== Payload Details ===');
|
||||
for (let i = 0; i < env.payloads.length; i++) {
|
||||
const payload = env.payloads[i];
|
||||
logTrace(`Payload ${i + 1} ('${payload.dataname}'):`);
|
||||
logTrace(` Transport: ${payload.transport}`);
|
||||
logTrace(` Type: ${payload.payload_type}`);
|
||||
logTrace(` Size: ${payload.size} bytes`);
|
||||
logTrace(` Encoding: ${payload.encoding}`);
|
||||
|
||||
if (payload.transport === 'link') {
|
||||
logTrace(` URL: ${payload.data}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Summary
|
||||
console.log('\n=== Transport Summary ===');
|
||||
const directCount = env.payloads.filter(p => p.transport === 'direct').length;
|
||||
const linkCount = env.payloads.filter(p => p.transport === 'link').length;
|
||||
logTrace(`Direct transport: ${directCount} payloads`);
|
||||
logTrace(`Link transport: ${linkCount} payloads`);
|
||||
|
||||
// Validate envelope structure
|
||||
console.log('\n=== Validation ===');
|
||||
let passed = true;
|
||||
|
||||
if (env.payloads.length !== 11) {
|
||||
console.log(`❌ Expected 11 payloads, got ${env.payloads.length}`);
|
||||
passed = false;
|
||||
} else {
|
||||
console.log('✅ Correct number of payloads');
|
||||
}
|
||||
|
||||
// Test each payload
|
||||
const expectedDatanames = [
|
||||
'chat_text', 'chat_json', 'arrow_table_small', 'json_table_small',
|
||||
filename_small_image, 'arrow_table_large', 'json_table_large',
|
||||
filename_large_image, 'audio_clip_large', 'video_clip_large',
|
||||
'binary_file_large'
|
||||
];
|
||||
const expectedTypes = [
|
||||
'text', 'dictionary', 'arrowtable', 'jsontable', 'binary',
|
||||
'arrowtable', 'jsontable', 'binary', 'audio', 'video', 'binary'
|
||||
];
|
||||
|
||||
for (let i = 0; i < env.payloads.length; i++) {
|
||||
const payload = env.payloads[i];
|
||||
|
||||
if (payload.dataname !== expectedDatanames[i]) {
|
||||
console.log(`❌ Payload ${i + 1}: Expected dataname '${expectedDatanames[i]}', got '${payload.dataname}'`);
|
||||
passed = false;
|
||||
} else {
|
||||
console.log(`✅ Payload ${i + 1}: Correct dataname ('${payload.dataname}')`);
|
||||
}
|
||||
|
||||
if (payload.payload_type !== expectedTypes[i]) {
|
||||
console.log(`❌ Payload ${i + 1}: Expected type '${expectedTypes[i]}', got '${payload.payload_type}'`);
|
||||
passed = false;
|
||||
} else {
|
||||
console.log(`✅ Payload ${i + 1}: Correct type ('${payload.payload_type}')`);
|
||||
}
|
||||
|
||||
// Validate transport based on expected size
|
||||
if (i < 5 || i >= 6 && i <= 10) {
|
||||
// First 5 should be direct (small), rest should be link (large)
|
||||
const shouldBeDirect = i < 5;
|
||||
const isDirect = payload.transport === 'direct';
|
||||
|
||||
if (shouldBeDirect && isDirect) {
|
||||
console.log(`✅ Payload ${i + 1}: Correct transport (direct)`);
|
||||
} else if (!shouldBeDirect && payload.transport === 'link') {
|
||||
console.log(`✅ Payload ${i + 1}: Correct transport (link)`);
|
||||
} else {
|
||||
console.log(`❌ Payload ${i + 1}: Expected ${shouldBeDirect ? 'direct' : 'link'} transport, got '${payload.transport}'`);
|
||||
passed = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate encoding based on payload type
|
||||
let expectedEncoding;
|
||||
if (payload.payload_type === 'jsontable') {
|
||||
expectedEncoding = 'json';
|
||||
} else if (payload.payload_type === 'arrowtable') {
|
||||
expectedEncoding = 'arrow-ipc';
|
||||
} else {
|
||||
expectedEncoding = 'base64';
|
||||
}
|
||||
|
||||
if (payload.encoding !== expectedEncoding) {
|
||||
console.log(`❌ Payload ${i + 1}: Expected encoding '${expectedEncoding}', got '${payload.encoding}'`);
|
||||
passed = false;
|
||||
} else {
|
||||
console.log(`✅ Payload ${i + 1}: Correct encoding ('${payload.encoding}')`);
|
||||
}
|
||||
|
||||
// Validate size field
|
||||
if (payload.size > 0) {
|
||||
console.log(`✅ Payload ${i + 1}: Size field present (${payload.size} bytes)`);
|
||||
} else {
|
||||
console.log(`❌ Payload ${i + 1}: Size field is 0`);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
// Validate ID field
|
||||
if (payload.id && payload.id.length > 0) {
|
||||
console.log(`✅ Payload ${i + 1}: ID field present`);
|
||||
} else {
|
||||
console.log(`❌ Payload ${i + 1}: ID field is empty`);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
// Validate metadata field
|
||||
if (payload.metadata !== undefined && payload.metadata !== null) {
|
||||
console.log(`✅ Payload ${i + 1}: Metadata field present`);
|
||||
} else {
|
||||
console.log(`❌ Payload ${i + 1}: Metadata field is missing`);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
console.log('');
|
||||
}
|
||||
|
||||
// Test with chat-like payload (text + image + audio)
|
||||
console.log('=== Chat-like Payload Test ===');
|
||||
const chatData = [
|
||||
['text', 'Hello!', 'text'],
|
||||
['image', Buffer.from([0xFF, 0xD8, 0xFF, 0xE0]), 'image'],
|
||||
['audio', Buffer.from([0x46, 0x4C, 0x41, 0x43]), 'audio']
|
||||
];
|
||||
|
||||
const [chatEnv, _] = await NATSBridge.smartsend(
|
||||
TEST_SUBJECT,
|
||||
chatData,
|
||||
{
|
||||
broker_url: TEST_BROKER_URL,
|
||||
fileserver_url: TEST_FILESERVER_URL,
|
||||
correlation_id: 'chat-' + correlationId,
|
||||
msg_purpose: 'chat',
|
||||
sender_name: 'js-mix-test',
|
||||
is_publish: true
|
||||
}
|
||||
);
|
||||
|
||||
if (chatEnv.payloads.length === 3) {
|
||||
console.log('✅ Chat-like payloads handled correctly (3 payloads)');
|
||||
} else {
|
||||
console.log(`❌ Chat-like payloads handling failed (expected 3, got ${chatEnv.payloads.length})`);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
// Verify all payload types in chat are direct transport
|
||||
const allDirect = chatEnv.payloads.every(p => p.transport === 'direct');
|
||||
if (allDirect) {
|
||||
console.log('✅ All chat payloads use direct transport (small size)');
|
||||
} else {
|
||||
console.log('❌ Some chat payloads use link transport (unexpected for small data)');
|
||||
passed = false;
|
||||
}
|
||||
|
||||
// Final result
|
||||
console.log('\n=== Test Result ===');
|
||||
if (passed) {
|
||||
console.log('✅ ALL TESTS PASSED');
|
||||
console.log('\nNote: Run test_js_mix_payloads_receiver.js to receive the messages.');
|
||||
process.exit(0);
|
||||
} else {
|
||||
console.log('❌ SOME TESTS FAILED');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('\n❌ Test failed with error:', error.message);
|
||||
console.error(error.stack);
|
||||
|
||||
Reference in New Issue
Block a user