v1rtlV
Denoβ€’3y agoβ€’
9 replies
v1rtl

error: BadResource: Bad resource ID

I'm writing tests for https://github.com/deno-libs/tinyhttp/pull/9.

import { describe, expect, it, run } from 'https://deno.land/x/tincan@1.0.1/mod.ts'
import { App } from '../../app.ts'

describe('Request properties', () => {
  it.only('should have default HTTP Request properties', async () => {
    const app = new App()
    app.get('/', (req, res) => {
      res.json({ url: req.url })
    })
    const listener = Deno.listen({ port: 8080, hostname: 'localhost' })

    setTimeout(() => {
      fetch(`http://localhost:8080`).then((res) => res.json()).then((json) => {
        expect(json).toEqual({ url: `http://localhost:8080/` }) 
      })
    }, 0)

    const conn = await listener.accept()
    const requests = Deno.serveHttp(conn)
    const { request, respondWith } = (await requests.nextRequest())!
    const response = await app.handler(request, conn)
    if (response) {
      respondWith(response)
      // Deno.close(conn.rid)
      
      listener.close()
    }
  })
})


When running this test I get either this:

Request properties > should have default HTTP Request properties => https://deno.land/x/tincan@1.0.1/src/runner.ts:166:10
error: BadResource: Bad resource ID
      Deno.close(conn.rid)
           ^
    at Object.close (ext:core/01_core.js:396:25)
    at ItNode.fn (file:///home/v1rtl/Coding/deno-libs/tinyhttp/tests/core/request.test.ts:29:12)
    at async wrappedFn (https://deno.land/x/tincan@1.0.1/src/runner.ts:141:9)


or this, if I uncomment that line:

error: AssertionError: Test case is leaking 1 resource:
 - An inbound HTTP connection (rid 8) was accepted during the test, but not closed during the test. Close the inbound HTTP connection by calling `httpConn.close()`.
    at assert (ext:deno_web/00_infra.js:353:11)
    at resourceSanitizer (ext:cli/40_testing.js:414:5)
    at async Object.exitSanitizer [as fn] (ext:cli/40_testing.js:432:7)
GitHub
GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 330 million projects.
Build software better, together
Was this page helpful?