deno.land / std@0.166.0 / node / _tools / test / parallel / test-dgram-socket-buffer-size.js

test-dgram-socket-buffer-size.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// deno-fmt-ignore-file// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.// Taken from Node 16.13.0// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Flags: --expose-internals'use strict';
const common = require('../common');const assert = require('assert');const dgram = require('dgram');const { inspect } = require('util');const { internalBinding } = require('internal/test/binding');const { UV_EBADF, UV_EINVAL, UV_ENOTSOCK} = internalBinding('uv');
// Note error test amendments from Node due to Deno formatting errors slightly// differently.function getExpectedError(type) { const code = common.isWindows ? 'ENOTSOCK' : 'EBADF'; const message = common.isWindows ? 'socket operation on non-socket' : 'bad file descriptor'; const errno = common.isWindows ? UV_ENOTSOCK : UV_EBADF; const syscall = `uv_${type}_buffer_size`; const suffix = common.isWindows ? 'ENOTSOCK (socket operation on non-socket)' : 'EBADF (bad file descriptor)'; const error = { code: 'ERR_SOCKET_BUFFER_SIZE', name: 'SystemError', message: `Could not get or set buffer size: ${syscall} returned ${suffix}`, info: { code, message, errno, syscall } }; return error;}
{ // Should throw error if the socket is never bound. const errorObj = getExpectedError('send');
const socket = dgram.createSocket('udp4');
assert.throws(() => { socket.setSendBufferSize(8192); }, (err) => { assert.strictEqual( inspect(err).replace(/^ +at .*\n/gm, ""), `ERR_SOCKET_BUFFER_SIZE [SystemError]: ${errorObj.message}\n` + " code: 'ERR_SOCKET_BUFFER_SIZE',\n" + " info: {\n" + ` errno: ${errorObj.info.errno},\n` + ` code: '${errorObj.info.code}',\n` + ` message: '${errorObj.info.message}',\n` + ` syscall: '${errorObj.info.syscall}'\n` + " },\n" + ` errno: [Getter/Setter],\n` + ` syscall: [Getter/Setter]\n` + "}" ); return true; });
assert.throws(() => { socket.getSendBufferSize(); }, errorObj);}
{ const socket = dgram.createSocket('udp4');
// Should throw error if the socket is never bound. const errorObj = getExpectedError('recv');
assert.throws(() => { socket.setRecvBufferSize(8192); }, errorObj);
assert.throws(() => { socket.getRecvBufferSize(); }, errorObj);}
{ // Should throw error if invalid buffer size is specified const errorObj = { code: 'ERR_SOCKET_BAD_BUFFER_SIZE', name: 'TypeError', message: /^Buffer size must be a positive integer$/ };
const badBufferSizes = [-1, Infinity, 'Doh!'];
const socket = dgram.createSocket('udp4');
socket.bind(common.mustCall(() => { badBufferSizes.forEach((badBufferSize) => { assert.throws(() => { socket.setRecvBufferSize(badBufferSize); }, errorObj);
assert.throws(() => { socket.setSendBufferSize(badBufferSize); }, errorObj); }); socket.close(); }));}
{ // Can set and get buffer sizes after binding the socket. const socket = dgram.createSocket('udp4');
socket.bind(common.mustCall(() => { socket.setRecvBufferSize(10000); socket.setSendBufferSize(10000);
// note: linux will double the buffer size const expectedBufferSize = common.isLinux ? 20000 : 10000; assert.strictEqual(socket.getRecvBufferSize(), expectedBufferSize); assert.strictEqual(socket.getSendBufferSize(), expectedBufferSize); socket.close(); }));}
{ const info = { code: 'EINVAL', message: 'invalid argument', errno: UV_EINVAL, syscall: 'uv_recv_buffer_size' }; const errorObj = { code: 'ERR_SOCKET_BUFFER_SIZE', name: 'SystemError', message: 'Could not get or set buffer size: uv_recv_buffer_size ' + 'returned EINVAL (invalid argument)', info }; const socket = dgram.createSocket('udp4'); socket.bind(common.mustCall(() => { assert.throws(() => { socket.setRecvBufferSize(2147483648); }, errorObj); socket.close(); }));}
{ const info = { code: 'EINVAL', message: 'invalid argument', errno: UV_EINVAL, syscall: 'uv_send_buffer_size' }; const errorObj = { code: 'ERR_SOCKET_BUFFER_SIZE', name: 'SystemError', message: 'Could not get or set buffer size: uv_send_buffer_size ' + 'returned EINVAL (invalid argument)', info }; const socket = dgram.createSocket('udp4'); socket.bind(common.mustCall(() => { assert.throws(() => { socket.setSendBufferSize(2147483648); }, errorObj); socket.close(); }));}
std

Version Info

Tagged at
a year ago