Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Fix DNS lookup in remote-method test #1937

Merged
merged 2 commits into from Jan 10, 2024

Conversation

jsumners-nr
Copy link
Contributor

The current test relies on whatever DNS server the system uses to return a "not found" answer for failed.domain.clxrg. There are two problems with this:

  1. A unit test, in my opinion, should not rely on any external resources (servers) in order to work.
  2. AT&T seems to ship gateways that will resolve whatever random domain you give them to arbitrary IP addresses.

This PR solves both problems.

@bizob2828 bizob2828 added the dev:tests Indicates only changes to tests label Jan 9, 2024
@@ -261,6 +262,16 @@ tap.test('when the connection fails', (t) => {
})

t.test('should correctly handle a DNS lookup failure', (t) => {
const lookup = dns.lookup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine but could just use sinon too

    const err = Error('no dns')
    err.code = dns.NOTFOUND
    sinon.stub(dns, 'lookup').yields(err)
    t.teardown(() => {
      dns.lookup.restore()
    })

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that provide anything we need here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really. we typically use sinon for mocking but older tests will still have patching style like this. I just wanted to call it out, feel free to merge

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not at all familiar with the sinon API. I like the least amount of mystery in tests as possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fair. I suggest you familiarize yourself as this repo does use it heavily. but again not a big deal here

bizob2828
bizob2828 previously approved these changes Jan 9, 2024
@@ -261,6 +262,16 @@ tap.test('when the connection fails', (t) => {
})

t.test('should correctly handle a DNS lookup failure', (t) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you also want to mock the test above too?

Copy link

codecov bot commented Jan 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (3e79cc7) 97.02% compared to head (1eccd85) 97.02%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1937   +/-   ##
=======================================
  Coverage   97.02%   97.02%           
=======================================
  Files         215      215           
  Lines       40239    40239           
=======================================
  Hits        39040    39040           
  Misses       1199     1199           
Flag Coverage Δ
integration-tests-16.x 78.92% <ø> (+0.01%) ⬆️
integration-tests-18.x 79.17% <ø> (-0.02%) ⬇️
integration-tests-20.x 79.19% <ø> (+0.01%) ⬆️
unit-tests-16.x 91.10% <ø> (ø)
unit-tests-18.x 91.08% <ø> (ø)
unit-tests-20.x 91.08% <ø> (ø)
versioned-tests-16.x 73.96% <ø> (-0.03%) ⬇️
versioned-tests-18.x 73.98% <ø> (-0.03%) ⬇️
versioned-tests-20.x 73.99% <ø> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bizob2828 bizob2828 merged commit 4da2149 into newrelic:main Jan 10, 2024
23 checks passed
Node.js Engineering Board automation moved this from Needs PR Review to Done: Issues recently completed Jan 10, 2024
@jsumners-nr jsumners-nr deleted the fix-test branch January 10, 2024 15:04
@github-actions github-actions bot mentioned this pull request Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev:tests Indicates only changes to tests
Projects
Node.js Engineering Board
  
Done: Issues recently completed
Development

Successfully merging this pull request may close these issues.

None yet

2 participants