sync-rpc 1.3.2 → 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,8 @@ test('it should work', () => {
7
7
  }
8
8
  });
9
9
 
10
+ let nativeNCFails = false;
11
+
10
12
  rpc.FUNCTION_PRIORITY.forEach((fn, i) => {
11
13
  test('profile ' + fn.name, () => {
12
14
  try {
@@ -18,7 +20,56 @@ rpc.FUNCTION_PRIORITY.forEach((fn, i) => {
18
20
  const end = Date.now();
19
21
  console.log(fn.name + ': ' + (end - start));
20
22
  } catch (ex) {
21
- console.log(fn.name + ' fails');
23
+ if (fn.name === 'nativeNC') {
24
+ console.log(fn.name + ' fails');
25
+ nativeNCFails = true;
26
+ return;
27
+ }
28
+ throw ex;
29
+ }
30
+ });
31
+ });
32
+
33
+ rpc.FUNCTION_PRIORITY.forEach((fn, i) => {
34
+ test('test 30MB ' + fn.name, () => {
35
+ let result;
36
+ try {
37
+ rpc.configuration.fastestFunction = fn;
38
+ result = client('big');
39
+ } catch (ex) {
40
+ if (fn.name === 'nativeNC' && nativeNCFails) {
41
+ console.log(fn.name + ' fails');
42
+ return;
43
+ }
44
+ throw ex;
45
+ }
46
+ expect(result.length).toBe(30 * 1024 * 1024, 42);
47
+ // for (let i = 0; i < 30 * 1024 * 1024, 42; i++) {
48
+ // expect(result[i]).toBe(42);
49
+ // }
50
+ });
51
+ });
52
+
53
+ rpc.FUNCTION_PRIORITY.forEach((fn, i) => {
54
+ let longMessage = '';
55
+ for (let i = 0; i < 100000; i++) {
56
+ longMessage += 'My Long Message Content';
57
+ }
58
+ test('profile large ' + fn.name, () => {
59
+ try {
60
+ rpc.configuration.fastestFunction = fn;
61
+ const start = Date.now();
62
+ for (let i = 0; i < 10; i++) {
63
+ expect(client(longMessage)).toBe(`sent ${longMessage} to My Server`);
64
+ }
65
+ const end = Date.now();
66
+ console.log('large ' + fn.name + ': ' + (end - start));
67
+ } catch (ex) {
68
+ if (fn.name === 'nativeNC' && nativeNCFails) {
69
+ console.log('large ' + fn.name + ' fails');
70
+ return;
71
+ }
72
+ throw ex;
22
73
  }
23
74
  });
24
75
  });
package/lib/index.js CHANGED
@@ -32,6 +32,7 @@ function start() {
32
32
  const port = findPort();
33
33
  const p = spawn(process.execPath, [require.resolve('./worker'), port], {
34
34
  stdio: 'inherit',
35
+ windowsHide: true,
35
36
  });
36
37
  p.unref();
37
38
  process.on('exit', () => {
@@ -45,21 +46,25 @@ function start() {
45
46
  }
46
47
 
47
48
  function findPort() {
48
- const findPortResult = spawnSync(process.execPath, [
49
- require.resolve('./find-port'),
50
- ]);
51
- if (findPortResult.status !== 0) {
52
- throw new Error(
53
- findPortResult.stderr.toString() ||
54
- 'find port exited with code ' + findPortResult.status
55
- );
56
- }
49
+ const findPortResult = spawnSync(
50
+ process.execPath,
51
+ [require.resolve('./find-port')],
52
+ {
53
+ windowsHide: true,
54
+ }
55
+ );
57
56
  if (findPortResult.error) {
58
57
  if (typeof findPortResult.error === 'string') {
59
58
  throw new Error(findPortResult.error);
60
59
  }
61
60
  throw findPortResult.error;
62
61
  }
62
+ if (findPortResult.status !== 0) {
63
+ throw new Error(
64
+ findPortResult.stderr.toString() ||
65
+ 'find port exited with code ' + findPortResult.status
66
+ );
67
+ }
63
68
  const portString = findPortResult.stdout.toString('utf8').trim();
64
69
  if (!/^[0-9]+$/.test(portString)) {
65
70
  throw new Error('Invalid port number string returned: ' + portString);
@@ -87,11 +92,27 @@ function waitForAlive(port) {
87
92
  }
88
93
 
89
94
  function nativeNC(port, input) {
90
- return spawnSync('nc', [host, port], {input: input});
95
+ return spawnSync('nc', [host, port], {
96
+ input: input,
97
+ windowsHide: true,
98
+ maxBuffer: Infinity,
99
+ });
91
100
  }
92
101
 
93
102
  function nodeNC(port, input) {
94
- return spawnSync(process.execPath, ['-e', nodeNetCatSrc(port, input)]);
103
+ const src = nodeNetCatSrc(port, input);
104
+ if (src.length < 1000) {
105
+ return spawnSync(process.execPath, ['-e', src], {
106
+ windowsHide: true,
107
+ maxBuffer: Infinity,
108
+ });
109
+ } else {
110
+ return spawnSync(process.execPath, [], {
111
+ input: src,
112
+ windowsHide: true,
113
+ maxBuffer: Infinity,
114
+ });
115
+ }
95
116
  }
96
117
 
97
118
  function test(fn, port) {
@@ -117,6 +138,10 @@ function sendMessage(input) {
117
138
  try {
118
139
  return JSON.parse(res.stdout.toString('utf8'));
119
140
  } catch (ex) {
141
+ if (res.error) {
142
+ if (typeof res.error === 'string') res.error = new Error(res.error);
143
+ throw res.error;
144
+ }
120
145
  if (res.status !== 0) {
121
146
  throw new Error(
122
147
  configuration.fastestFunction.name +
@@ -126,10 +151,6 @@ function sendMessage(input) {
126
151
  (res.stderr && res.stderr.toString())
127
152
  );
128
153
  }
129
- if (res.error) {
130
- if (typeof res.error === 'string') res.error = new Error(res.error);
131
- throw res.error;
132
- }
133
154
  throw new Error(
134
155
  configuration.fastestFunction.name +
135
156
  ' failed:\n' +
@@ -1,5 +1,8 @@
1
1
  function init(connection) {
2
2
  return function(message) {
3
+ if (message === 'big') {
4
+ return Promise.resolve(Buffer.alloc(30 * 1024 * 1024, 42));
5
+ }
3
6
  return Promise.resolve('sent ' + message + ' to ' + connection);
4
7
  };
5
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sync-rpc",
3
- "version": "1.3.2",
3
+ "version": "1.3.6",
4
4
  "main": "lib/index.js",
5
5
  "description": "Run asynchronous commands synchronously by putting them in a separate process",
6
6
  "keywords": [],