Skip to content

Commit 706bfc8

Browse files
authored
Merge pull request #168 from yfyf/macos-tests-and-ci
Fix macOS tests and enable them in CI
2 parents 0b99fb1 + a1ed855 commit 706bfc8

8 files changed

Lines changed: 39 additions & 29 deletions

File tree

.github/workflows/test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ jobs:
2727
- uses: DeterminateSystems/magic-nix-cache-action@v11
2828
- run: nix develop --command make crossbuild
2929

30-
crossbuild-mac:
30+
test-and-crossbuild-mac:
3131
runs-on: macos-latest
3232
steps:
3333
- uses: actions/checkout@v4
3434
- uses: cachix/install-nix-action@v31
3535
with:
3636
github_access_token: ${{ secrets.GITHUB_TOKEN }}
3737
- uses: DeterminateSystems/magic-nix-cache-action@v11
38+
- run: nix develop --command make build
39+
- run: nix develop --command make test
3840
- run: nix develop --command make crossbuild_mac
3941
- run: nix develop --command make crossbuild_mac_bundles

test/cors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-env mocha */
22

3-
const { wait, getJSON, startDriver, connectWS } = require('./utils')
3+
const { wait, getJSON, startDriver, connectWS, waitForEndpoint } = require('./utils')
44
const expect = require('chai').expect
55

66
const httpEndpoints = [
@@ -24,7 +24,7 @@ beforeEach(async () => {
2424
driver = startDriver(...permissibleOrigins.flatMap(origin => [ '--permissible-origin', origin ])).on('exit', (c) => {
2525
code = c
2626
})
27-
await wait(500)
27+
await waitForEndpoint('http://127.0.0.1:8382/');
2828
expect(code).to.be.equal(0)
2929
driver.removeAllListeners()
3030
})

test/flex/helpers.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
const { wait } = require("../utils");
22

3-
async function waitForEndpoint(url, maxAttempts = 5, delay = 100) {
4-
let lastError = null;
5-
for (let i = 0; i < maxAttempts; i++) {
6-
try {
7-
// note: not connecting to websocket to avoid messing with test state by having a client
8-
const res = await fetch(url);
9-
return;
10-
} catch (e) {
11-
lastError = e;
12-
await wait(delay);
13-
}
14-
}
15-
throw new Error(`Endpoint ${url} not available after ${maxAttempts} attempts, last error: ${e}`);
16-
}
17-
183
/**
194
* Generate a single synthetic Flex serial data frame.
205
*
@@ -135,7 +120,6 @@ function splitBufferRandomly(buffer, minChunkSize = 1, maxChunkSize = 10) {
135120
}
136121

137122
module.exports = {
138-
waitForEndpoint,
139123
generateFlexSerialFrame,
140124
generateSensitronicsFrame,
141125
generateRandomSensitronicsFrame,

test/flex/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
const { wait, startDriver, connectWS, expectEvent } = require("../utils");
1+
const { wait, startDriver, connectWS, expectEvent, waitForEndpoint } = require("../utils");
22
const expect = require("chai").expect;
33
const VirtualDevice = require("./mock/VirtualDevice");
44
const path = require("path");
55
const {
6-
waitForEndpoint,
76
generateFlexSerialFrame,
87
generateRandomSensitronicsFrame,
98
splitBufferRandomly,

test/general.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-env mocha */
22

3-
const { wait, getJSON, startDriver } = require('./utils')
3+
const { wait, getJSON, startDriver, waitForEndpoint } = require('./utils')
44
const expect = require('chai').expect
55

66
var driver
@@ -10,7 +10,7 @@ beforeEach(async () => {
1010
driver = startDriver().on('exit', (c) => {
1111
code = c
1212
})
13-
await wait(500)
13+
await waitForEndpoint('http://127.0.0.1:8382');
1414
expect(code).to.be.equal(0)
1515
driver.removeAllListeners()
1616
})

test/rfid/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-env mocha */
2-
const { wait, startDriver, connectWS, getJSON, expectEvent } = require('../utils')
2+
const { wait, startDriver, connectWS, getJSON, expectEvent, waitForEndpoint } = require('../utils')
33
const expect = require('chai').expect
44

55
// TESTS
@@ -14,8 +14,7 @@ describe('Basic functionality', () => {
1414
driver = startDriver().on('exit', (c) => {
1515
code = c
1616
})
17-
// Give driver 500ms to start up
18-
await wait(500)
17+
await waitForEndpoint('http://127.0.0.1:8382/rfid');
1918
expect(code).to.be.equal(0)
2019
driver.removeAllListeners()
2120
})

test/senso/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-env mocha */
2-
const { wait, startDriver, connectWS, expectEvent } = require('../utils')
2+
const { wait, startDriver, connectWS, expectEvent, waitForEndpoint, skipTestOnMacOSinCI } = require('../utils')
33
const expect = require('chai').expect
44

55
const mock = require('./mock')
@@ -16,8 +16,7 @@ describe('Basic functionality', () => {
1616
driver = startDriver().on('exit', (c) => {
1717
code = c
1818
})
19-
// Give driver 500ms to start up
20-
await wait(500)
19+
await waitForEndpoint('http://127.0.0.1:8382/senso');
2120
expect(code).to.be.equal(0)
2221
driver.removeAllListeners()
2322

@@ -213,6 +212,8 @@ describe('Basic functionality', () => {
213212
})
214213

215214
it('Can discover mock Senso', async function () {
215+
// bonjour / mDNS does not seem to work on Github's macOS runners
216+
skipTestOnMacOSinCI(this)
216217
this.timeout(6000)
217218

218219
// connect with Senso WS

test/utils.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,30 @@ module.exports = {
4848
}
4949
})
5050
})
51+
},
52+
53+
// Checks whether a connection can be established via HTTP to URL, regardless
54+
// of status code.
55+
waitForEndpoint: async function(url, maxAttempts = 10, delay = 100) {
56+
let lastError = null
57+
for (let i = 0; i < maxAttempts; i++) {
58+
try {
59+
const res = await fetch(url)
60+
return
61+
} catch (e) {
62+
lastError = e
63+
await module.exports.wait(delay)
64+
}
65+
}
66+
throw new Error(`Endpoint ${url} not available after ${maxAttempts} attempts, last error: ${e}`)
67+
},
68+
69+
skipTestOnMacOSinCI: function (test) {
70+
const isMac = process.platform === 'darwin'
71+
const isGitHubActions = process.env.GITHUB_ACTIONS === 'true'
72+
73+
if (isMac && isGitHubActions) {
74+
test.skip()
75+
}
5176
}
5277
}

0 commit comments

Comments
 (0)