Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@v11
- run: nix develop --command make crossbuild

crossbuild-mac:
test-and-crossbuild-mac:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v31
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- uses: DeterminateSystems/magic-nix-cache-action@v11
- run: nix develop --command make build
- run: nix develop --command make test
- run: nix develop --command make crossbuild_mac
- run: nix develop --command make crossbuild_mac_bundles
4 changes: 2 additions & 2 deletions test/cors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env mocha */

const { wait, getJSON, startDriver, connectWS } = require('./utils')
const { wait, getJSON, startDriver, connectWS, waitForEndpoint } = require('./utils')
const expect = require('chai').expect

const httpEndpoints = [
Expand All @@ -24,7 +24,7 @@ beforeEach(async () => {
driver = startDriver(...permissibleOrigins.flatMap(origin => [ '--permissible-origin', origin ])).on('exit', (c) => {
code = c
})
await wait(500)
await waitForEndpoint('http://127.0.0.1:8382/');
expect(code).to.be.equal(0)
driver.removeAllListeners()
})
Expand Down
16 changes: 0 additions & 16 deletions test/flex/helpers.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
const { wait } = require("../utils");

async function waitForEndpoint(url, maxAttempts = 5, delay = 100) {
let lastError = null;
for (let i = 0; i < maxAttempts; i++) {
try {
// note: not connecting to websocket to avoid messing with test state by having a client
const res = await fetch(url);
return;
} catch (e) {
lastError = e;
await wait(delay);
}
}
throw new Error(`Endpoint ${url} not available after ${maxAttempts} attempts, last error: ${e}`);
}

/**
* Generate a single synthetic Flex serial data frame.
*
Expand Down Expand Up @@ -135,7 +120,6 @@ function splitBufferRandomly(buffer, minChunkSize = 1, maxChunkSize = 10) {
}

module.exports = {
waitForEndpoint,
generateFlexSerialFrame,
generateSensitronicsFrame,
generateRandomSensitronicsFrame,
Expand Down
3 changes: 1 addition & 2 deletions test/flex/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const { wait, startDriver, connectWS, expectEvent } = require("../utils");
const { wait, startDriver, connectWS, expectEvent, waitForEndpoint } = require("../utils");
const expect = require("chai").expect;
const VirtualDevice = require("./mock/VirtualDevice");
const path = require("path");
const {
waitForEndpoint,
generateFlexSerialFrame,
generateRandomSensitronicsFrame,
splitBufferRandomly,
Expand Down
4 changes: 2 additions & 2 deletions test/general.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env mocha */

const { wait, getJSON, startDriver } = require('./utils')
const { wait, getJSON, startDriver, waitForEndpoint } = require('./utils')
const expect = require('chai').expect

var driver
Expand All @@ -10,7 +10,7 @@ beforeEach(async () => {
driver = startDriver().on('exit', (c) => {
code = c
})
await wait(500)
await waitForEndpoint('http://127.0.0.1:8382');
expect(code).to.be.equal(0)
driver.removeAllListeners()
})
Expand Down
5 changes: 2 additions & 3 deletions test/rfid/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-env mocha */
const { wait, startDriver, connectWS, getJSON, expectEvent } = require('../utils')
const { wait, startDriver, connectWS, getJSON, expectEvent, waitForEndpoint } = require('../utils')
const expect = require('chai').expect

// TESTS
Expand All @@ -14,8 +14,7 @@ describe('Basic functionality', () => {
driver = startDriver().on('exit', (c) => {
code = c
})
// Give driver 500ms to start up
await wait(500)
await waitForEndpoint('http://127.0.0.1:8382/rfid');
expect(code).to.be.equal(0)
driver.removeAllListeners()
})
Expand Down
7 changes: 4 additions & 3 deletions test/senso/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-env mocha */
const { wait, startDriver, connectWS, expectEvent } = require('../utils')
const { wait, startDriver, connectWS, expectEvent, waitForEndpoint, skipTestOnMacOSinCI } = require('../utils')
const expect = require('chai').expect

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

Expand Down Expand Up @@ -213,6 +212,8 @@ describe('Basic functionality', () => {
})

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

// connect with Senso WS
Expand Down
25 changes: 25 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,30 @@ module.exports = {
}
})
})
},

// Checks whether a connection can be established via HTTP to URL, regardless
// of status code.
waitForEndpoint: async function(url, maxAttempts = 10, delay = 100) {
let lastError = null
for (let i = 0; i < maxAttempts; i++) {
try {
const res = await fetch(url)
return
} catch (e) {
lastError = e
await module.exports.wait(delay)
}
}
throw new Error(`Endpoint ${url} not available after ${maxAttempts} attempts, last error: ${e}`)
},

skipTestOnMacOSinCI: function (test) {
const isMac = process.platform === 'darwin'
const isGitHubActions = process.env.GITHUB_ACTIONS === 'true'

if (isMac && isGitHubActions) {
test.skip()
}
}
}