Skip to content

Commit b491efc

Browse files
committed
fix coverage of UDP Exporter
1 parent 2fe7b93 commit b491efc

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

aws-distro-opentelemetry-node-autoinstrumentation/test/otlp-udp-exporter.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ describe('UdpExporterTest', () => {
6969
expect(diagErrorSpy.notCalled).toBe(true);
7070
});
7171

72+
it('should handle synchronous errors when sending UDP data', async () => {
73+
const errorMessage = 'Synchronous UDP send error';
74+
socketSend.throws(new Error(errorMessage)); // Simulate synchronous error
75+
76+
const data = new Uint8Array([1, 2, 3]);
77+
await expect(udpExporter.sendData(data, 'T1')).rejects.toThrow(errorMessage);
78+
expect(diagErrorSpy.calledOnce).toBe(true);
79+
expect(diagErrorSpy.calledWith('Error sending UDP data: %s', sinon.match.instanceOf(Error))).toBe(true);
80+
});
81+
7282
it('should close the socket on shutdown', () => {
7383
udpExporter.shutdown();
7484
expect(socketClose.calledOnce).toBe(true);
@@ -183,4 +193,12 @@ describe('OTLPUdpSpanExporterTest', () => {
183193
await otlpUdpSpanExporter.shutdown();
184194
expect(udpExporterMock.shutdown.calledOnce).toBe(true);
185195
});
196+
197+
it('should handle shutdown errors', async () => {
198+
const shutdownError = new Error('Shutdown error');
199+
udpExporterMock.shutdown.reset();
200+
udpExporterMock.shutdown.throws(shutdownError);
201+
202+
await expect(otlpUdpSpanExporter.shutdown()).rejects.toThrow('Shutdown error');
203+
});
186204
});

exporters/aws-distro-opentelemetry-exporter-xray-udp/test/aws-xray-udp-span-exporter.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ describe('UdpExporterTest', () => {
7070
expect(diagErrorSpy.notCalled).toBe(true);
7171
});
7272

73+
it('should handle synchronous errors when sending UDP data', async () => {
74+
const errorMessage = 'Synchronous UDP send error';
75+
socketSend.throws(new Error(errorMessage)); // Simulate synchronous error
76+
77+
const data = new Uint8Array([1, 2, 3]);
78+
await expect(udpExporter.sendData(data, 'T1')).rejects.toThrow(errorMessage);
79+
expect(diagErrorSpy.calledOnce).toBe(true);
80+
expect(diagErrorSpy.calledWith('Error sending UDP data: %s', sinon.match.instanceOf(Error))).toBe(true);
81+
});
82+
7383
it('should close the socket on shutdown', () => {
7484
udpExporter.shutdown();
7585
expect(socketClose.calledOnce).toBe(true);
@@ -195,6 +205,14 @@ describe('AwsXrayUdpSpanExporterTest', () => {
195205
expect(udpExporterMock.shutdown.calledOnce).toBe(true);
196206
});
197207

208+
it('should handle shutdown errors', async () => {
209+
const shutdownError = new Error('Shutdown error');
210+
udpExporterMock.shutdown.reset();
211+
udpExporterMock.shutdown.throws(shutdownError);
212+
213+
await expect(awsXrayUdpSpanExporter.shutdown()).rejects.toThrow('Shutdown error');
214+
});
215+
198216
it('should use expected Environment Variables to configure endpoint', () => {
199217
process.env.AWS_LAMBDA_FUNCTION_NAME = 'testFunctionName';
200218
process.env.AWS_XRAY_DAEMON_ADDRESS = 'someaddress:1234';

0 commit comments

Comments
 (0)