Skip to content

Commit

Permalink
test: updated the grpc versioned tests utils to dynamically bind port…
Browse files Browse the repository at this point in the history
…s to avoid conflicts between cjs and esm tests (#1820)
  • Loading branch information
bizob2828 committed Oct 17, 2023
1 parent 317a00a commit 95ac917
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 66 deletions.
12 changes: 6 additions & 6 deletions test/versioned/grpc-esm/client-unary.tap.mjs
Expand Up @@ -26,14 +26,13 @@ tap.test('gRPC Client: Unary Requests', (t) => {
let server
let proto
let grpc
let port

t.before(async () => {
agent = helper.instrumentMockedAgent()
grpc = await import('@grpc/grpc-js')
const data = await createServer(grpc)
proto = data.proto
server = data.server
client = getClient(grpc, proto)
;({ proto, server, port } = await createServer(grpc))
client = getClient(grpc, proto, port)
})

t.afterEach(() => {
Expand All @@ -55,7 +54,7 @@ tap.test('gRPC Client: Unary Requests', (t) => {
function transactionFinished(transaction) {
if (transaction.name === 'clientTransaction') {
// Make sure we're in the client and not server transaction
assertExternalSegment({ t, tx: transaction, fnName: 'SayHello' })
assertExternalSegment({ t, tx: transaction, fnName: 'SayHello', port })
t.end()
}
}
Expand Down Expand Up @@ -119,7 +118,7 @@ tap.test('gRPC Client: Unary Requests', (t) => {
const response = await makeUnaryRequest({ client, fnName: 'sayHello', payload })
t.ok(response, 'response exists')
t.equal(response.message, 'Hello New Relic', 'response message is correct')
assertMetricsNotExisting({ t, agent })
assertMetricsNotExisting({ t, agent, port })
t.end()
})

Expand All @@ -140,6 +139,7 @@ tap.test('gRPC Client: Unary Requests', (t) => {
function transactionFinished(transaction) {
if (transaction.name === 'clientTransaction') {
assertError({
port,
t,
transaction,
errors: agent.errors,
Expand Down
7 changes: 3 additions & 4 deletions test/versioned/grpc-esm/server-unary.tap.mjs
Expand Up @@ -30,14 +30,13 @@ tap.test('gRPC Server: Unary Requests', (t) => {
let server
let proto
let grpc
let port

t.before(async () => {
agent = helper.instrumentMockedAgent()
grpc = await import('@grpc/grpc-js')
const data = await createServer(grpc)
proto = data.proto
server = data.server
client = getClient(grpc, proto)
;({ proto, server, port } = await createServer(grpc))
client = getClient(grpc, proto, port)
})

t.afterEach(() => {
Expand Down
12 changes: 6 additions & 6 deletions test/versioned/grpc/client-bidi-streaming.tap.js
Expand Up @@ -26,14 +26,13 @@ tap.test('gRPC Client: Bidi Streaming', (t) => {
let server
let proto
let grpc
let port

t.beforeEach(async () => {
agent = helper.instrumentMockedAgent()
grpc = require('@grpc/grpc-js')
const data = await createServer(grpc)
proto = data.proto
server = data.server
client = getClient(grpc, proto)
;({ port, proto, server } = await createServer(grpc))
client = getClient(grpc, proto, port)
})

t.afterEach(() => {
Expand All @@ -57,7 +56,7 @@ tap.test('gRPC Client: Bidi Streaming', (t) => {
agent.on('transactionFinished', (transaction) => {
if (transaction.name === 'clientTransaction') {
// Make sure we're in the client and not server transaction
assertExternalSegment({ t, tx: transaction, fnName: 'SayHelloBidiStream' })
assertExternalSegment({ t, tx: transaction, fnName: 'SayHelloBidiStream', port })
t.end()
}
})
Expand Down Expand Up @@ -141,7 +140,7 @@ tap.test('gRPC Client: Bidi Streaming', (t) => {
payload.forEach(({ name }, i) => {
t.equal(responses[i], `Hello ${name}`, 'response stream message should be correct')
})
assertMetricsNotExisting({ t, agent })
assertMetricsNotExisting({ t, agent, port })
t.end()
}
)
Expand All @@ -164,6 +163,7 @@ tap.test('gRPC Client: Bidi Streaming', (t) => {
agent.on('transactionFinished', (transaction) => {
if (transaction.name === 'clientTransaction') {
assertError({
port,
t,
transaction,
errors: agent.errors,
Expand Down
12 changes: 6 additions & 6 deletions test/versioned/grpc/client-server-streaming.tap.js
Expand Up @@ -26,14 +26,13 @@ tap.test('gRPC Client: Server Streaming', (t) => {
let server
let proto
let grpc
let port

t.beforeEach(async () => {
agent = helper.instrumentMockedAgent()
grpc = require('@grpc/grpc-js')
const data = await createServer(grpc)
proto = data.proto
server = data.server
client = getClient(grpc, proto)
;({ port, proto, server } = await createServer(grpc))
client = getClient(grpc, proto, port)
})

t.afterEach(() => {
Expand All @@ -55,7 +54,7 @@ tap.test('gRPC Client: Server Streaming', (t) => {
agent.on('transactionFinished', (transaction) => {
if (transaction.name === 'clientTransaction') {
// Make sure we're in the client and not server transaction
assertExternalSegment({ t, tx: transaction, fnName: 'SayHelloServerStream' })
assertExternalSegment({ t, tx: transaction, fnName: 'SayHelloServerStream', port })
t.end()
}
})
Expand Down Expand Up @@ -124,7 +123,7 @@ tap.test('gRPC Client: Server Streaming', (t) => {
})
t.ok(responses.length, 1)
t.equal(responses[0], 'Hello New Relic', 'response message is correct')
assertMetricsNotExisting({ t, agent })
assertMetricsNotExisting({ t, agent, port })
t.end()
})

Expand All @@ -146,6 +145,7 @@ tap.test('gRPC Client: Server Streaming', (t) => {
agent.on('transactionFinished', (transaction) => {
if (transaction.name === 'clientTransaction') {
assertError({
port,
t,
transaction,
errors: agent.errors,
Expand Down
13 changes: 7 additions & 6 deletions test/versioned/grpc/client-streaming.tap.js
Expand Up @@ -26,14 +26,13 @@ tap.test('gRPC Client: Client Streaming', (t) => {
let server
let proto
let grpc
let port

t.beforeEach(async () => {
agent = helper.instrumentMockedAgent()
grpc = require('@grpc/grpc-js')
const data = await createServer(grpc)
proto = data.proto
server = data.server
client = getClient(grpc, proto)
;({ port, proto, server } = await createServer(grpc))
client = getClient(grpc, proto, port)
})

t.afterEach(() => {
Expand All @@ -55,7 +54,7 @@ tap.test('gRPC Client: Client Streaming', (t) => {
agent.on('transactionFinished', (transaction) => {
if (transaction.name === 'clientTransaction') {
// Make sure we're in the client and not server transaction
assertExternalSegment({ t, tx: transaction, fnName: 'SayHelloClientStream' })
assertExternalSegment({ t, tx: transaction, fnName: 'SayHelloClientStream', port })
t.end()
}
})
Expand Down Expand Up @@ -127,7 +126,7 @@ tap.test('gRPC Client: Client Streaming', (t) => {
})
t.ok(response, 'response exists')
t.equal(response.message, 'Hello New Relic', 'response message is correct')
assertMetricsNotExisting({ t, agent })
assertMetricsNotExisting({ t, agent, port })
t.end()
})

Expand All @@ -149,6 +148,7 @@ tap.test('gRPC Client: Client Streaming', (t) => {
agent.on('transactionFinished', (transaction) => {
if (transaction.name === 'clientTransaction') {
assertError({
port,
t,
transaction,
errors: agent.errors,
Expand Down Expand Up @@ -183,6 +183,7 @@ tap.test('gRPC Client: Client Streaming', (t) => {
agent.on('transactionFinished', (transaction) => {
if (transaction.name === 'clientTransaction') {
assertError({
port,
t,
transaction,
errors: agent.errors,
Expand Down
12 changes: 6 additions & 6 deletions test/versioned/grpc/client-unary.tap.js
Expand Up @@ -26,14 +26,13 @@ tap.test('gRPC Client: Unary Requests', (t) => {
let server
let proto
let grpc
let port

t.beforeEach(async () => {
agent = helper.instrumentMockedAgent()
grpc = require('@grpc/grpc-js')
const data = await createServer(grpc)
proto = data.proto
server = data.server
client = getClient(grpc, proto)
;({ proto, server, port } = await createServer(grpc))
client = getClient(grpc, proto, port)
})

t.afterEach(() => {
Expand All @@ -55,7 +54,7 @@ tap.test('gRPC Client: Unary Requests', (t) => {
agent.on('transactionFinished', (transaction) => {
if (transaction.name === 'clientTransaction') {
// Make sure we're in the client and not server transaction
assertExternalSegment({ t, tx: transaction, fnName: 'SayHello' })
assertExternalSegment({ t, tx: transaction, fnName: 'SayHello', port })
t.end()
}
})
Expand Down Expand Up @@ -116,7 +115,7 @@ tap.test('gRPC Client: Unary Requests', (t) => {
const response = await makeUnaryRequest({ client, fnName: 'sayHello', payload })
t.ok(response, 'response exists')
t.equal(response.message, 'Hello New Relic', 'response message is correct')
assertMetricsNotExisting({ t, agent })
assertMetricsNotExisting({ t, agent, port })
t.end()
})

Expand All @@ -138,6 +137,7 @@ tap.test('gRPC Client: Unary Requests', (t) => {
agent.on('transactionFinished', (transaction) => {
if (transaction.name === 'clientTransaction') {
assertError({
port,
t,
transaction,
errors: agent.errors,
Expand Down
7 changes: 3 additions & 4 deletions test/versioned/grpc/server-bidi-streaming.tap.js
Expand Up @@ -30,14 +30,13 @@ tap.test('gRPC Server: Bidi Streaming', (t) => {
let server
let proto
let grpc
let port

t.beforeEach(async () => {
agent = helper.instrumentMockedAgent()
grpc = require('@grpc/grpc-js')
const data = await createServer(grpc)
proto = data.proto
server = data.server
client = getClient(grpc, proto)
;({ port, proto, server } = await createServer(grpc))
client = getClient(grpc, proto, port)
})

t.afterEach(() => {
Expand Down
7 changes: 3 additions & 4 deletions test/versioned/grpc/server-client-streaming.tap.js
Expand Up @@ -30,14 +30,13 @@ tap.test('gRPC Server: Client Streaming', (t) => {
let server
let proto
let grpc
let port

t.beforeEach(async () => {
agent = helper.instrumentMockedAgent()
grpc = require('@grpc/grpc-js')
const data = await createServer(grpc)
proto = data.proto
server = data.server
client = getClient(grpc, proto)
;({ port, proto, server } = await createServer(grpc))
client = getClient(grpc, proto, port)
})

t.afterEach(() => {
Expand Down
7 changes: 3 additions & 4 deletions test/versioned/grpc/server-streaming.tap.js
Expand Up @@ -30,14 +30,13 @@ tap.test('gRPC Server: Server Streaming', (t) => {
let server
let proto
let grpc
let port

t.beforeEach(async () => {
agent = helper.instrumentMockedAgent()
grpc = require('@grpc/grpc-js')
const data = await createServer(grpc)
proto = data.proto
server = data.server
client = getClient(grpc, proto)
;({ port, proto, server } = await createServer(grpc))
client = getClient(grpc, proto, port)
})

t.afterEach(() => {
Expand Down
7 changes: 3 additions & 4 deletions test/versioned/grpc/server-unary.tap.js
Expand Up @@ -30,14 +30,13 @@ tap.test('gRPC Server: Unary Requests', (t) => {
let server
let proto
let grpc
let port

t.beforeEach(async () => {
agent = helper.instrumentMockedAgent()
grpc = require('@grpc/grpc-js')
const data = await createServer(grpc)
proto = data.proto
server = data.server
client = getClient(grpc, proto)
;({ port, proto, server } = await createServer(grpc))
client = getClient(grpc, proto, port)
})

t.afterEach(() => {
Expand Down

0 comments on commit 95ac917

Please sign in to comment.