Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add webkit test script #1627

Merged
merged 21 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7d73f81
Add webkit test script
MarcoPolo Mar 15, 2023
cfd5c4b
Add webkit test to CI
MarcoPolo Mar 16, 2023
c3cde5e
Install playwright deps
MarcoPolo Mar 20, 2023
c77c006
Merge branch 'master' into marco/js-libp2p-test-webkit
achingbrain Apr 30, 2023
6cc9030
Fix stream stubbing. We can't set the property value like this on safari
MarcoPolo May 2, 2023
5ed2146
Bump @libp2p/crypto
MarcoPolo May 2, 2023
111ba6b
Update @libp2p/crypto
MarcoPolo May 5, 2023
f288f82
Merge branch 'master' into marco/js-libp2p-test-webkit
MarcoPolo May 5, 2023
bc177f5
Merge remote-tracking branch 'origin/master' into marco/js-libp2p-tes…
achingbrain May 18, 2023
36c38ba
Merge branch 'master' into marco/js-libp2p-test-webkit
maschad May 23, 2023
2f0dde9
refactor: updated formatters
maschad May 23, 2023
3da460d
Merge branch 'master' into marco/js-libp2p-test-webkit
maschad May 26, 2023
ede58c6
Merge branch 'master' into marco/js-libp2p-test-webkit
maschad May 31, 2023
3d6a67e
test: skip flaky connect and disconnect event tests
maschad May 31, 2023
8e43bb5
deps: update logger to enable multiaddr formatting
maschad May 31, 2023
a78db93
test: ensure that libp2p nodes are shutdown in identify service spec
maschad Jun 1, 2023
5a24425
chore: linting fixes
maschad Jun 1, 2023
c21177e
chore: remove webkit fixes
achingbrain Jun 2, 2023
d29de4a
refactor: updated multiaddr formatting in logs
maschad Jun 3, 2023
34cdc28
Merge branch 'master' into marco/js-libp2p-test-webkit
achingbrain Jun 6, 2023
37044fa
chore: edits for consistency
achingbrain Jun 6, 2023
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
16 changes: 16 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ jobs:
directory: ./.nyc_output
flags: firefox-webworker

test-webkit:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
- run: npx playwright install-deps
- run: npm run --if-present test:webkit
- uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0
with:
directory: ./.nyc_output
flags: webkit

test-electron-main:
needs: check
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion examples/libp2p-in-the-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"license": "ISC",
"dependencies": {
"@chainsafe/libp2p-gossipsub": "^7.0.0",
"@chainsafe/libp2p-gossipsub": "^8.0.0",
"@chainsafe/libp2p-noise": "^12.0.0",
"@chainsafe/libp2p-yamux": "^4.0.1",
"@libp2p/bootstrap": "^8.0.0",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,13 @@
"test:chrome-webworker": "aegir test -t webworker -f \"./dist/test/**/*.spec.js\"",
"test:firefox": "aegir test -t browser -f \"./dist/test/**/*.spec.js\" -- --browser firefox",
"test:firefox-webworker": "aegir test -t webworker -f \"./dist/test/**/*.spec.js\" -- --browser firefox",
"test:webkit": "aegir test -t browser -f \"./dist/test/**/*.spec.js\" -- --browser webkit",
"test:examples": "cd examples && npm run test:all",
"test:interop": "aegir test -t node -f dist/test/interop.js"
},
"dependencies": {
"@achingbrain/nat-port-mapper": "^1.0.3",
"@libp2p/crypto": "^1.0.4",
"@libp2p/crypto": "^1.0.17",
"@libp2p/interface-address-manager": "^3.0.0",
"@libp2p/interface-connection": "^5.0.0",
"@libp2p/interface-connection-encrypter": "^4.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/autonat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ class DefaultAutoNATService implements Startable {
// they either told us which address worked/didn't work, or we only sent them one address
const addr = dialResponse.addr == null ? multiaddrs[0] : multiaddr(dialResponse.addr)

log('Autonat response for %s is %s', addr, dialResponse.status)
log('Autonat response for %s is %s', addr.toString(), dialResponse.status)
maschad marked this conversation as resolved.
Show resolved Hide resolved

if (dialResponse.status === Message.ResponseStatus.E_BAD_REQUEST) {
// the remote could not parse our request
Expand Down Expand Up @@ -551,7 +551,7 @@ class DefaultAutoNATService implements Startable {

if (results[addrStr].failure === REQUIRED_SUCCESSFUL_DIALS) {
// we are now unconvinced
log('%s is not externally dialable', addr)
log('%s is not externally dialable', addr.toString())
achingbrain marked this conversation as resolved.
Show resolved Hide resolved
addressManager.removeObservedAddr(addr)
return
}
Expand Down
40 changes: 26 additions & 14 deletions test/autonat/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@

import { start, stop } from '@libp2p/interfaces/startable'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { type Multiaddr, multiaddr } from '@multiformats/multiaddr'
import { multiaddr } from '@multiformats/multiaddr'
import { expect } from 'aegir/chai'
import all from 'it-all'
import * as lp from 'it-length-prefixed'
import { pipe } from 'it-pipe'
import { pushable } from 'it-pushable'
import sinon from 'sinon'
import { type StubbedInstance, stubInterface } from 'sinon-ts'
import { stubInterface, stubObject } from 'sinon-ts'
import { Uint8ArrayList } from 'uint8arraylist'
import { PROTOCOL_NAME, PROTOCOL_PREFIX, PROTOCOL_VERSION } from '../../src/autonat/constants.js'
import { autoNATService, type AutoNATServiceInit } from '../../src/autonat/index.js'
import { autoNATService } from '../../src/autonat/index.js'
import { Message } from '../../src/autonat/pb/index.js'
import { type Components, defaultComponents } from '../../src/components.js'
import { defaultComponents } from '../../src/components.js'
import type { AutoNATServiceInit } from '../../src/autonat/index.js'
import type { Components } from '../../src/components.js'
import type { DefaultConnectionManager } from '../../src/connection-manager/index.js'
import type { AddressManager } from '@libp2p/interface-address-manager'
import type { Connection, Stream } from '@libp2p/interface-connection'
Expand All @@ -25,6 +27,8 @@ import type { PeerRouting } from '@libp2p/interface-peer-routing'
import type { PeerStore } from '@libp2p/interface-peer-store'
import type { Registrar } from '@libp2p/interface-registrar'
import type { Transport, TransportManager } from '@libp2p/interface-transport'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { StubbedInstance } from 'sinon-ts'

const defaultInit: AutoNATServiceInit = {
protocolPrefix: 'libp2p',
Expand Down Expand Up @@ -92,19 +96,28 @@ describe('autonat', () => {
connection.remoteAddr = multiaddr(`/ip4/${host}/tcp/28319/p2p/${peer.id.toString()}`)
connectionManager.openConnection.withArgs(peer.id).resolves(connection)

// stub autonat protocol stream
const stream = stubInterface<Stream>()
connection.newStream.withArgs(`/${PROTOCOL_PREFIX}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`).resolves(stream)

// stub autonat response
const response = Message.encode({
type: Message.MessageType.DIAL_RESPONSE,
dialResponse
})
stream.source = (async function * () {
yield lp.encode.single(response)
}())
stream.sink.returns(Promise.resolve())

// stub autonat protocol stream
const stream = stubObject<Stream>({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to run this branch locally I noticed something weird with the stubbing but only in WebKit, though I didn't get to the bottom of it.

We stub a bunch of peer responses in each test to simulate different scenarios - once a certain number of tests were being run, the stubbed return values started being from the wrong tests.

Needs more investigation really.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Hence this change. I'm not sure why exactly this fails on WebKit but seems to work on other browsers. I'm not sure overriding values is supported in Sinon or if it's a hack we do. The change here is to not override and instead be explicit in what gets stubbed vs set.

My guess is the other failures we're seeing is related to something like this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked out the Sinon docs? I believe we’re using it as intended, no “hack” involved.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think sinon is not involved here. This should just be setting values on the object here: https://github.com/ttarnowski/ts-sinon/blob/master/src/index.ts#L67. Maybe Proxy in WebKit has slightly different behavior? Maybe a bug since this only shows up in certain cases (e.g. run only this test is fine, but run two versions of this test fails).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it’s really weird because we don’t reuse the stubbed instances between the tests that I can see 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maschad did you figure out what the issue was here around Proxy?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarcoPolo I don't think the issue was related to Proxy but rather the peer id fixtures, the relay server behaved as if it was creating reservations for peers that seemed to be reconnecting due to the tests reusing peer ids, we resolved this in this PR

close: sinon.stub(),
closeRead: sinon.stub(),
closeWrite: sinon.stub(),
abort: sinon.stub(),
reset: sinon.stub(),
id: '',
stat: { direction: 'outbound', timeline: { open: Date.now() } },
metadata: {},
source: (async function * () {
// stub autonat response
yield lp.encode.single(response)
}()),
sink: sinon.stub().returns(Promise.resolve())
})
connection.newStream.withArgs(`/${PROTOCOL_PREFIX}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`).resolves(stream)

return peer
}
Expand Down Expand Up @@ -289,7 +302,6 @@ describe('autonat', () => {
status: Message.ResponseStatus.E_DIAL_ERROR
})
]

peerRouting.getClosestPeers.returns(async function * () {
yield * peers
}())
Expand Down