Skip to content

Commit

Permalink
[#193] gRPC DataSource specific method Test Fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
feelform committed Aug 2, 2024
1 parent 94cfe72 commit 642d799
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions test/client/grpc-unary-rpc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,35 @@ function before(port, serviceConfig) {
return dataSenderFactory.create(actualConfig, agentInfo())
}

function beforeOne(port, one, serviceConfig) {
config.clear()
const actualConfig = config.getConfig({ 'grpc.service_config': serviceConfig })
actualConfig.collectorIp = 'localhost'
actualConfig.collectorTcpPort = port
actualConfig.collectorStatPort = port
actualConfig.collectorSpanPort = port
actualConfig.enabledDataSending = true
return new one(
actualConfig.collectorIp,
actualConfig.collectorTcpPort,
actualConfig.collectorStatPort,
actualConfig.collectorSpanPort,
agentInfo(),
actualConfig
)
}

class GrpcAgentInfoOnlyDataSource extends GrpcDataSender {
constructor(collectorIp, collectorTcpPort, collectorStatPort, collectorSpanPort, agentInfo, config) {
super(collectorIp, collectorTcpPort, collectorStatPort, collectorSpanPort, agentInfo, config)
}
initializeMetadataClients() { }
initializeSpanStream() { }
initializeStatStream() { }
initializePingStream() { }
initializeAgentInfoScheduler() { }
}

let tryShutdown
test.skip('AgentInfo with retries enabled but not configured', (t) => {
const server = new grpc.Server()
Expand Down Expand Up @@ -115,7 +144,7 @@ test('AgentInfo with retries enabled and configured', (t) => {

let dataSender
server.bindAsync('localhost:0', grpc.ServerCredentials.createInsecure(), (error, port) => {
dataSender = before(port, {
dataSender = beforeOne(port, GrpcAgentInfoOnlyDataSource, {
methodConfig: [
{
name: [
Expand All @@ -139,14 +168,14 @@ test('AgentInfo with retries enabled and configured', (t) => {
t.true(response.getSuccess(), '1st PResult.success is true')
t.equal(response.getMessage(), 'succeed-on-retry-attempt: undefined, grpc-previous-rpc-attempts: undefined, delay-time: undefined', '1st PResult.message is "succeed-on-retry-attempt: undefined, grpc-previous-rpc-attempts: undefined, delay-time: undefined"')
}).build()
dataSender.dataSender.sendAgentInfo(agentInfo(), callArguments)
dataSender.sendAgentInfo(agentInfo(), callArguments)

callArguments = new CallArgumentsBuilder(function (error, response) {
// t.true(response.getSuccess(), '2nd PResult.success is true')
}).setMetadata('succeed-on-retry-attempt', '2')
.setMetadata('respond-with-status', '14')
.build()
dataSender.dataSender.sendAgentInfo(agentInfo(), callArguments)
dataSender.sendAgentInfo(agentInfo(), callArguments)

callArguments = new CallArgumentsBuilder(function (error, response) {
if (error) {
Expand All @@ -156,7 +185,7 @@ test('AgentInfo with retries enabled and configured', (t) => {
t.equal(response.getMessage(), 'succeed-on-retry-attempt: undefined, grpc-previous-rpc-attempts: undefined, delay-time: undefined', '3st PResult.message is "succeed-on-retry-attempt: undefined, grpc-previous-rpc-attempts: undefined, delay-time: undefined"')
t.end()
}).build()
dataSender.dataSender.sendAgentInfo(agentInfo(), callArguments)
dataSender.sendAgentInfo(agentInfo(), callArguments)
})

t.teardown(() => {
Expand Down

0 comments on commit 642d799

Please sign in to comment.