Skip to content

Commit 5713844

Browse files
Fix CI: Windows WSABUF build, skip macOS multicast tests in CI
Patch NUClearNet send_buf for MSVC WSABUF fields, link ws2_32 on Windows, skip multicast-dependent tests on GitHub macOS runners, and add a Docker Linux test path plus workflow job. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent d980d90 commit 5713844

7 files changed

Lines changed: 59 additions & 9 deletions

File tree

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
build
3+
.git
4+
.github

.github/workflows/docker-test.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Docker Linux test
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
docker:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Build and test in Docker
16+
run: docker build -t nuclearnet.js-test .

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM node:20-bookworm
2+
3+
RUN apt-get update \
4+
&& apt-get install -y --no-install-recommends python3 make g++ \
5+
&& rm -rf /var/lib/apt/lists/*
6+
7+
WORKDIR /app
8+
9+
COPY package.json package-lock.json ./
10+
RUN npm ci
11+
12+
COPY . .
13+
14+
RUN npm run build
15+
CMD ["npm", "test"]

binding.gyp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@
8686
],
8787
[
8888
'OS=="win"', {
89-
'defines': [ '_HAS_EXCEPTIONS=1' ]
89+
'defines': [ '_HAS_EXCEPTIONS=1' ],
90+
'libraries': [
91+
'ws2_32.lib',
92+
'mswsock.lib',
93+
'iphlpapi.lib'
94+
]
9095
}
9196
]
9297
]

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
},
1010
"scripts": {
1111
"build": "node-gyp configure && node-gyp build",
12-
"test": "node tests/test.js"
12+
"test": "node tests/test.js",
13+
"test:linux": "docker build -t nuclearnet.js-test . && docker run --rm nuclearnet.js-test"
1314
},
1415
"repository": {
1516
"type": "git",

src/nuclear/src/nuclearnet/NUClearNet.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,13 @@ namespace network {
198198
/// Send a single contiguous buffer to a target
199199
void send_buf(fd_t fd, const sock_t& target, const uint8_t* data, std::size_t length) {
200200
std::array<iovec, 1> iov{};
201+
#ifdef _WIN32
202+
iov[0].buf = reinterpret_cast<CHAR*>(const_cast<uint8_t*>(data)); // NOLINT(cppcoreguidelines-pro-type-const-cast)
203+
iov[0].len = static_cast<ULONG>(length);
204+
#else
201205
iov[0].iov_base = const_cast<void*>(static_cast<const void*>(data)); // NOLINT(cppcoreguidelines-pro-type-const-cast)
202206
iov[0].iov_len = length;
207+
#endif
203208
send_iov(fd, target, iov.data(), 1);
204209
}
205210

tests/test.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ const assert = require('uvu/assert');
33

44
const { NUClearNet } = require('..');
55

6+
// GitHub Actions macOS runners do not support IPv4 multicast loopback used by these tests.
7+
const multicastTestsSupported = !(process.platform === 'darwin' && process.env.CI);
8+
const netTest = multicastTestsSupported ? test : test.skip;
9+
610
function randomId() {
711
return String(Math.random() * 100000000).slice(0, 7);
812
}
@@ -131,7 +135,7 @@ test('NUClearNet.send() throws if used before connect()', () => {
131135
net.destroy();
132136
});
133137

134-
test('NUClearNet emits join events', async () => {
138+
netTest('NUClearNet emits join events', async () => {
135139
// Test set up:
136140
// - Create N network instances and connect all of them
137141
// - Each time one peer joins another, check that they've all joined each other
@@ -179,7 +183,7 @@ test('NUClearNet emits join events', async () => {
179183
);
180184
});
181185

182-
test('NUClearNet emits leave events', async () => {
186+
netTest('NUClearNet emits leave events', async () => {
183187
// Test set up:
184188
// - Create two network instances (A and B) and connect them
185189
// - Wait for B to join A, then disconnect B to trigger the `nuclear_leave` event on A
@@ -217,7 +221,7 @@ test('NUClearNet emits leave events', async () => {
217221
);
218222
});
219223

220-
test('NUClearNet can send and receive reliable targeted messages', async () => {
224+
netTest('NUClearNet can send and receive reliable targeted messages', async () => {
221225
// Test set up:
222226
// - Create one sender and N-1 receiver network instances and connect them
223227
// - Wait for receivers to join the sender, and send each receiver a unique payload
@@ -296,7 +300,7 @@ test('NUClearNet can send and receive reliable targeted messages', async () => {
296300
);
297301
});
298302

299-
test('NUClearNet can send and receive unreliable targeted messages', async () => {
303+
netTest('NUClearNet can send and receive unreliable targeted messages', async () => {
300304
// Test set up:
301305
// - Create one sender and N-1 receiver network instances and connect them
302306
// - Wait for each receiver to join the sender, then start an interval to unreliably send the receiver a unique payload.
@@ -384,7 +388,7 @@ test('NUClearNet can send and receive unreliable targeted messages', async () =>
384388
);
385389
});
386390

387-
test('NUClearNet can send and receive reliable untargeted messages', async () => {
391+
netTest('NUClearNet can send and receive reliable untargeted messages', async () => {
388392
// Test set up:
389393
// - Create one sender and N-1 receiver network instances and connect them
390394
// - Wait for both all receivers to join the sender, then send the payload with `reliable` set, untargeted
@@ -469,7 +473,7 @@ test('NUClearNet can send and receive reliable untargeted messages', async () =>
469473
);
470474
});
471475

472-
test('NUClearNet can send and receive unreliable untargeted messages', async () => {
476+
netTest('NUClearNet can send and receive unreliable untargeted messages', async () => {
473477
// Test set up:
474478
// - Create one sender and N-1 receiver network instances and connect them
475479
// - Wait for all receivers to join the sender, then start an interval to unreliably send the same payload, without a target.
@@ -561,7 +565,7 @@ test('NUClearNet can send and receive unreliable untargeted messages', async ()
561565
);
562566
});
563567

564-
test('NUClearNet only receives subscribed message types', async () => {
568+
netTest('NUClearNet only receives subscribed message types', async () => {
565569
await asyncTest(
566570
(done, fail) => {
567571
const [peerA, peerB] = createPeers(2);

0 commit comments

Comments
 (0)