Skip to content

Commit

Permalink
test: Migrated memcached tests to versioned tests (#2231)
Browse files Browse the repository at this point in the history
  • Loading branch information
bizob2828 authored May 30, 2024
1 parent 9a4dddc commit 0b3a928
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 42 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm install
- name: Run Docker Services
run: npm run services
- name: Run Integration Tests
run: npm run integration
- name: Run ESM Integration Tests
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@
"koa-router": "^12.0.1",
"lint-staged": "^11.0.0",
"lockfile-lint": "^4.9.6",
"memcached": ">=0.2.8",
"nock": "11.8.0",
"proxy": "^2.1.1",
"proxyquire": "^1.8.0",
Expand Down
16 changes: 0 additions & 16 deletions test/lib/agent_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const path = require('path')
const fs = require('fs').promises
const Agent = require('../../lib/agent')
const API = require('../../api')
const params = require('../lib/params')
const zlib = require('zlib')
const copy = require('../../lib/util/copy')
const { defaultAttributeConfig } = require('./fixtures')
Expand Down Expand Up @@ -312,21 +311,6 @@ helper.runInSegment = (agent, name, callback) => {
return tracer.addSegment(name, null, null, null, callback)
}

/**
* Stub to bootstrap a memcached instance
*
* @param {Function} callback The operations to be performed while the server
* is running.
*/
helper.bootstrapMemcached = (callback) => {
const Memcached = require('memcached')
const memcached = new Memcached(params.memcached_host + ':' + params.memcached_port)
memcached.flush((err) => {
memcached.end()
callback(err)
})
}

/**
* Select Redis DB index and flush entries in it.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,22 @@ const findSegment = require('../../lib/metrics_helper').findSegment
const getMetricHostName = require('../../lib/metrics_helper').getMetricHostName
const util = require('util')

const bootstrapMemcached = util.promisify(helper.bootstrapMemcached)

const METRICS_ASSERTIONS = 10

/**
* Flushes memcached to start clean
*
* @param {object} memcached instance of memcached
*/
function flush(memcached) {
return new Promise((resolve, reject) => {
memcached.flush((err) => {
memcached.end()
err ? reject(err) : resolve()
})
})
}

test('memcached instrumentation', { timeout: 5000 }, function (t) {
t.autoend()

Expand All @@ -29,20 +41,17 @@ test('memcached instrumentation', { timeout: 5000 }, function (t) {
t.autoend()

t.beforeEach(async () => {
await bootstrapMemcached()

agent = helper.instrumentMockedAgent()

Memcached = require('memcached')
memcached = new Memcached(params.memcached_host + ':' + params.memcached_port)

const hostName = getMetricHostName(agent, params.memcached_host)
HOST_ID = hostName + '/' + params.memcached_port
})

t.afterEach(() => {
t.afterEach(async () => {
agent && helper.unloadAgent(agent)
memcached && memcached.end()
await flush(memcached)
})

t.test('touch()', function (t) {
Expand Down Expand Up @@ -412,8 +421,6 @@ test('memcached instrumentation', { timeout: 5000 }, function (t) {
t.autoend()

t.beforeEach(async () => {
await bootstrapMemcached()

agent = helper.instrumentMockedAgent()

// capture attributes
Expand All @@ -423,9 +430,9 @@ test('memcached instrumentation', { timeout: 5000 }, function (t) {
memcached = new Memcached(params.memcached_host + ':' + params.memcached_port)
})

t.afterEach(() => {
t.afterEach(async () => {
helper.unloadAgent(agent)
memcached.end()
await flush(memcached)
})

t.test('get()', function (t) {
Expand Down Expand Up @@ -494,17 +501,15 @@ test('memcached instrumentation', { timeout: 5000 }, function (t) {
t.autoend()

t.beforeEach(async () => {
await bootstrapMemcached()

agent = helper.instrumentMockedAgent()

Memcached = require('memcached')
memcached = new Memcached(params.memcached_host + ':' + params.memcached_port)
})

t.afterEach(() => {
t.afterEach(async () => {
helper.unloadAgent(agent)
memcached.end()
await flush(memcached)
})

t.test('get()', function (t) {
Expand Down Expand Up @@ -568,8 +573,6 @@ test('memcached instrumentation', { timeout: 5000 }, function (t) {
t.autoend()

t.beforeEach(async () => {
await bootstrapMemcached()

agent = helper.instrumentMockedAgent()

// disable
Expand All @@ -579,9 +582,9 @@ test('memcached instrumentation', { timeout: 5000 }, function (t) {
memcached = new Memcached(params.memcached_host + ':' + params.memcached_port)
})

t.afterEach(() => {
t.afterEach(async () => {
helper.unloadAgent(agent)
memcached.end()
await flush(memcached)
})

t.test('get()', function (t) {
Expand Down Expand Up @@ -643,8 +646,6 @@ test('memcached instrumentation', { timeout: 5000 }, function (t) {
const realServer = params.memcached_host + ':' + params.memcached_port

t.beforeEach(async () => {
await bootstrapMemcached()

Memcached = require('memcached')
origCommand = Memcached.prototype.command
/* eslint-disable no-unused-vars */
Expand All @@ -664,9 +665,9 @@ test('memcached instrumentation', { timeout: 5000 }, function (t) {
}
})

t.afterEach(() => {
t.afterEach(async () => {
helper.unloadAgent(agent)
memcached.end()
await flush(memcached)
if (origCommand) {
Memcached.prototype.command = origCommand
}
Expand Down
21 changes: 21 additions & 0 deletions test/versioned/memcached/newrelic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2024 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

'use strict'

exports.config = {
app_name: ['My Application'],
license_key: 'license key here',
utilization: {
detect_aws: false,
detect_pcf: false,
detect_azure: false,
detect_gcp: false,
detect_docker: false
},
logging: {
enabled: false
}
}
19 changes: 19 additions & 0 deletions test/versioned/memcached/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "memcached-test",
"targets": [{"name":"memcached","minAgentVersion":"1.26.2"}],
"version": "0.0.0",
"private": true,
"tests": [
{
"engines": {
"node": ">=16"
},
"dependencies": {
"memcached": ">=2.2.0"
},
"files": [
"memcached.tap.js"
]
}
]
}

0 comments on commit 0b3a928

Please sign in to comment.