Skip to content

Commit c725440

Browse files
authored
test: attempt to fix flaky windows CI (#197)
fixes #40
1 parent ff8e07c commit c725440

File tree

4 files changed

+44
-29
lines changed

4 files changed

+44
-29
lines changed

src/test/integration/filecoin-pin-store.integration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { rm, stat } from 'node:fs/promises'
2-
import { createHelia } from 'helia'
32
import { CID } from 'multiformats/cid'
43
import * as raw from 'multiformats/codecs/raw'
54
import { sha256 } from 'multiformats/hashes/sha2'
@@ -8,6 +7,7 @@ import { createConfig } from '../../config.js'
87
import { FilecoinPinStore } from '../../filecoin-pin-store.js'
98
import { createLogger } from '../../logger.js'
109
import { MockSynapse, mockProviderInfo } from '../mocks/synapse-mocks.js'
10+
import { createTestHelia } from '../mocks/test-helia.js'
1111

1212
// Mock the Synapse SDK - vi.mock requires async import for ES modules
1313
vi.mock('@filoz/synapse-sdk', async () => await import('../mocks/synapse-sdk.js'))
@@ -37,7 +37,7 @@ describe('FilecoinPinStore', () => {
3737
const logger = createLogger(config)
3838

3939
// Create a Helia node to serve content
40-
contentOriginHelia = await createHelia()
40+
contentOriginHelia = await createTestHelia()
4141

4242
// Create mock Synapse service
4343
const mockSynapse = new MockSynapse()

src/test/integration/integration.test.ts

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
import { readFile, rm, stat } from 'node:fs/promises'
2-
import { noise } from '@chainsafe/libp2p-noise'
3-
import { yamux } from '@chainsafe/libp2p-yamux'
42
import { SIZE_CONSTANTS } from '@filoz/synapse-sdk'
53
import { unixfs } from '@helia/unixfs'
64
import { CarReader } from '@ipld/car'
75
import * as dagCbor from '@ipld/dag-cbor'
8-
import { identify } from '@libp2p/identify'
9-
import { tcp } from '@libp2p/tcp'
10-
import { MemoryBlockstore } from 'blockstore-core'
11-
import { MemoryDatastore } from 'datastore-core'
12-
import { createHelia } from 'helia'
13-
import { createLibp2p } from 'libp2p'
146
import { CID } from 'multiformats/cid'
157
import * as raw from 'multiformats/codecs/raw'
168
import { sha256 } from 'multiformats/hashes/sha2'
179
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
1810
import { createConfig } from '../../config.js'
1911
import { createFilecoinPinningServer } from '../../filecoin-pinning-server.js'
2012
import { createLogger } from '../../logger.js'
13+
import { createTestHelia } from '../mocks/test-helia.js'
2114

2215
// Mock the Synapse SDK - vi.mock requires async import for ES modules
2316
vi.mock('@filoz/synapse-sdk', async (importOriginal) => {
@@ -64,23 +57,7 @@ describe('End-to-End Pinning Service', () => {
6457
const logger = createLogger(config)
6558

6659
// Create client Helia node (content provider)
67-
const libp2p = await createLibp2p({
68-
addresses: {
69-
listen: ['/ip4/127.0.0.1/tcp/0'], // Random port on localhost
70-
},
71-
transports: [tcp()],
72-
connectionEncrypters: [noise()],
73-
streamMuxers: [yamux()],
74-
services: {
75-
identify: identify(),
76-
},
77-
})
78-
79-
clientHelia = await createHelia({
80-
libp2p,
81-
blockstore: new MemoryBlockstore(),
82-
datastore: new MemoryDatastore(),
83-
})
60+
clientHelia = await createTestHelia()
8461

8562
// Create pinning server
8663
const serviceInfo = { service: 'filecoin-pin', version: '0.1.0' }

src/test/integration/simple-pin.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { rm, stat } from 'node:fs/promises'
2-
import { createHelia } from 'helia'
32
import { CID } from 'multiformats/cid'
43
import * as raw from 'multiformats/codecs/raw'
54
import { sha256 } from 'multiformats/hashes/sha2'
@@ -8,6 +7,7 @@ import { createConfig } from '../../config.js'
87
import { FilecoinPinStore } from '../../filecoin-pin-store.js'
98
import { createLogger } from '../../logger.js'
109
import { MockSynapse, mockProviderInfo } from '../mocks/synapse-mocks.js'
10+
import { createTestHelia } from '../mocks/test-helia.js'
1111

1212
// Mock the Synapse SDK - vi.mock requires async import for ES modules
1313
vi.mock('@filoz/synapse-sdk', async () => await import('../mocks/synapse-sdk.js'))
@@ -34,7 +34,7 @@ describe('Simple Pin Test', () => {
3434
const logger = createLogger(config)
3535

3636
// Create a Helia node to serve content
37-
contentOriginHelia = await createHelia()
37+
contentOriginHelia = await createTestHelia()
3838
await contentOriginHelia.blockstore.put(testCID, testBlock)
3939

4040
// Create mock Synapse service

src/test/mocks/test-helia.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { noise } from '@chainsafe/libp2p-noise'
2+
import { yamux } from '@chainsafe/libp2p-yamux'
3+
import { identify } from '@libp2p/identify'
4+
import { tcp } from '@libp2p/tcp'
5+
import { MemoryBlockstore } from 'blockstore-core'
6+
import { MemoryDatastore } from 'datastore-core'
7+
import { createHelia, type Helia } from 'helia'
8+
import { createLibp2p } from 'libp2p'
9+
10+
/**
11+
* Creates a Helia node for testing with TCP-only transport.
12+
*
13+
* This configuration avoids UDP socket issues that can occur on Windows CI
14+
* by using only TCP transport and localhost binding.
15+
*
16+
* @returns A Helia instance configured for testing
17+
*/
18+
export async function createTestHelia(): Promise<Helia> {
19+
// Create libp2p with TCP-only configuration to avoid UDP socket issues on Windows CI
20+
const libp2p = await createLibp2p({
21+
addresses: {
22+
listen: ['/ip4/127.0.0.1/tcp/0'], // Localhost only, random port
23+
},
24+
transports: [tcp()],
25+
connectionEncrypters: [noise()],
26+
streamMuxers: [yamux()],
27+
services: {
28+
identify: identify(),
29+
},
30+
})
31+
32+
// Create Helia with memory-based storage for tests
33+
return await createHelia({
34+
libp2p,
35+
blockstore: new MemoryBlockstore(),
36+
datastore: new MemoryDatastore(),
37+
})
38+
}

0 commit comments

Comments
 (0)