Skip to content

Commit

Permalink
test: Migrated memcached tests to versioned tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bizob2828 committed May 29, 2024
1 parent 85b3862 commit 35d401d
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 105 deletions.
37 changes: 5 additions & 32 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ code, the source code can be found at [https://github.com/newrelic/node-newrelic
* [koa](#koa)
* [lint-staged](#lint-staged)
* [lockfile-lint](#lockfile-lint)
* [memcached](#memcached)
* [nock](#nock)
* [proxy](#proxy)
* [proxyquire](#proxyquire)
Expand Down Expand Up @@ -94,7 +93,7 @@ code, the source code can be found at [https://github.com/newrelic/node-newrelic

### @grpc/grpc-js

This product includes source derived from [@grpc/grpc-js](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js) ([v1.10.7](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/tree/v1.10.7)), distributed under the [Apache-2.0 License](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/blob/v1.10.7/LICENSE):
This product includes source derived from [@grpc/grpc-js](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js) ([v1.10.8](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/tree/v1.10.8)), distributed under the [Apache-2.0 License](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/blob/v1.10.8/LICENSE):

```
Apache License
Expand Down Expand Up @@ -889,7 +888,7 @@ SOFTWARE.

### @aws-sdk/client-s3

This product includes source derived from [@aws-sdk/client-s3](https://github.com/aws/aws-sdk-js-v3) ([v3.572.0](https://github.com/aws/aws-sdk-js-v3/tree/v3.572.0)), distributed under the [Apache-2.0 License](https://github.com/aws/aws-sdk-js-v3/blob/v3.572.0/LICENSE):
This product includes source derived from [@aws-sdk/client-s3](https://github.com/aws/aws-sdk-js-v3) ([v3.582.0](https://github.com/aws/aws-sdk-js-v3/tree/v3.582.0)), distributed under the [Apache-2.0 License](https://github.com/aws/aws-sdk-js-v3/blob/v3.582.0/LICENSE):

```
Apache License
Expand Down Expand Up @@ -1098,7 +1097,7 @@ This product includes source derived from [@aws-sdk/client-s3](https://github.co

### @aws-sdk/s3-request-presigner

This product includes source derived from [@aws-sdk/s3-request-presigner](https://github.com/aws/aws-sdk-js-v3) ([v3.572.0](https://github.com/aws/aws-sdk-js-v3/tree/v3.572.0)), distributed under the [Apache-2.0 License](https://github.com/aws/aws-sdk-js-v3/blob/v3.572.0/LICENSE):
This product includes source derived from [@aws-sdk/s3-request-presigner](https://github.com/aws/aws-sdk-js-v3) ([v3.582.0](https://github.com/aws/aws-sdk-js-v3/tree/v3.582.0)), distributed under the [Apache-2.0 License](https://github.com/aws/aws-sdk-js-v3/blob/v3.582.0/LICENSE):

```
Apache License
Expand Down Expand Up @@ -2496,7 +2495,7 @@ THE SOFTWARE.

### aws-sdk

This product includes source derived from [aws-sdk](https://github.com/aws/aws-sdk-js) ([v2.1618.0](https://github.com/aws/aws-sdk-js/tree/v2.1618.0)), distributed under the [Apache-2.0 License](https://github.com/aws/aws-sdk-js/blob/v2.1618.0/LICENSE.txt):
This product includes source derived from [aws-sdk](https://github.com/aws/aws-sdk-js) ([v2.1626.0](https://github.com/aws/aws-sdk-js/tree/v2.1626.0)), distributed under the [Apache-2.0 License](https://github.com/aws/aws-sdk-js/blob/v2.1626.0/LICENSE.txt):

```
Expand Down Expand Up @@ -2895,7 +2894,7 @@ THE SOFTWARE.

### eslint-plugin-jsdoc

This product includes source derived from [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc) ([v48.2.4](https://github.com/gajus/eslint-plugin-jsdoc/tree/v48.2.4)), distributed under the [BSD-3-Clause License](https://github.com/gajus/eslint-plugin-jsdoc/blob/v48.2.4/LICENSE):
This product includes source derived from [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc) ([v48.2.5](https://github.com/gajus/eslint-plugin-jsdoc/tree/v48.2.5)), distributed under the [BSD-3-Clause License](https://github.com/gajus/eslint-plugin-jsdoc/blob/v48.2.5/LICENSE):

```
Copyright (c) 2018, Gajus Kuizinas (http://gajus.com/)
Expand Down Expand Up @@ -3673,32 +3672,6 @@ This product includes source derived from [lockfile-lint](https://github.com/lir
limitations under the License.
```

### memcached

This product includes source derived from [memcached](https://github.com/3rd-Eden/node-memcached) ([v2.2.2](https://github.com/3rd-Eden/node-memcached/tree/v2.2.2)), distributed under the [MIT License](https://github.com/3rd-Eden/node-memcached/blob/v2.2.2/LICENSE):

```
Copyright (c) 2010 Arnout Kazemier,3rd-Eden
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
```

### nock

This product includes source derived from [nock](https://github.com/nock/nock) ([v11.8.0](https://github.com/nock/nock/tree/v11.8.0)), distributed under the [MIT License](https://github.com/nock/nock/blob/v11.8.0/LICENSE):
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,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"
]
}
]
}
Loading

0 comments on commit 35d401d

Please sign in to comment.