<commit_before>local backend = require 'resty.http_ng.backend.async_resty'

describe('resty backend', function()

  describe('GET method #network', function()
    local method = 'GET'

    it('accesses the url', function()
      local response = backend:send{method = method, url = 'http://example.com/'}
      assert.truthy(response)
      assert.falsy(response.error)
      assert.truthy(response.ok)
      assert.equal(200, response.status)
      assert.equal('string', type(response.body))
      assert.truthy(response.request)
    end)

    it('works with ssl', function()
      local response, err = backend:send{
        method = method, url = 'https://google.com/',
        -- This is needed because of https://groups.google.com/forum/#!topic/openresty-en/SuqORBK9ys0
        -- So far OpenResty can't use system certificated on demand.
        options = { ssl = { verify = false } }
      }
      assert.falsy(err)
      assert.falsy(response.error)
      assert.truthy(response.ok)
      assert(response.headers.location:match('^https://'))
      assert.equal('string', type(response.body))
      assert.truthy(response.request)
    end)

    it('returns proper error on connect timeout', function()
      local req = { method = method, url = 'http://example.com:81/', timeout = { connect = 1 } }

      local response = backend:send(req)

      assert.truthy(response)
      assert.equal('timeout', response.error)
      assert.equal(req, response.request)
      assert.falsy(response.ok)
    end)

    it('returns proper error on read timeout', function()
      local req = { method = method, url = 'http://example.com/', timeout = { read = 1 } }

      local response = backend:send(req)

      assert.truthy(response)
      assert.equal('timeout', response.error)
      assert.equal(req, response.request)
      assert.falsy(response.ok)
    end)

    it('returns proper error on invalid ssl', function()
      local req = { method = method, url = 'https://untrusted-root.badssl.com/', options = { ssl = { verify = true } } }

      local response = backend:send(req)

      assert.truthy(response)
      assert.match('unable to get local issuer certificate', response.error)
      assert.equal(req, response.request)
      assert.falsy(response.ok)<commit_msg>[spec] use site that deterministically waits<commit_after>local backend = require 'resty.http_ng.backend.async_resty'

describe('resty backend', function()

  describe('GET method #network', function()
    local method = 'GET'

    it('accesses the url', function()
      local response = backend:send{method = method, url = 'http://example.com/'}
      assert.truthy(response)
      assert.falsy(response.error)
      assert.truthy(response.ok)
      assert.equal(200, response.status)
      assert.equal('string', type(response.body))
      assert.truthy(response.request)
    end)

    it('works with ssl', function()
      local response, err = backend:send{
        method = method, url = 'https://google.com/',
        -- This is needed because of https://groups.google.com/forum/#!topic/openresty-en/SuqORBK9ys0
        -- So far OpenResty can't use system certificated on demand.
        options = { ssl = { verify = false } }
      }
      assert.falsy(err)
      assert.falsy(response.error)
      assert.truthy(response.ok)
      assert(response.headers.location:match('^https://'))
      assert.equal('string', type(response.body))
      assert.truthy(response.request)
    end)

    it('returns proper error on connect timeout', function()
      local req = { method = method, url = 'http://example.com:81/', timeout = { connect = 1 } }

      local response = backend:send(req)

      assert.truthy(response)
      assert.equal('timeout', response.error)
      assert.equal(req, response.request)
      assert.falsy(response.ok)
    end)

    it('returns proper error on read timeout', function()
      local req = { method = method, url = 'http://httpbin.org/delay/1', timeout = { read = 1 } }

      local response = backend:send(req)

      assert.truthy(response)
      assert.equal('timeout', response.error)
      assert.equal(req, response.request)
      assert.falsy(response.ok)
    end)

    it('returns proper error on invalid ssl', function()
      local req = { method = method, url = 'https://untrusted-root.badssl.com/', options = { ssl = { verify = true } } }

      local response = backend:send(req)

      assert.truthy(response)
      assert.match('unable to get local issuer certificate', response.error)
      assert.equal(req, response.request)
      assert.falsy(response.ok)
{'fraction_non_alphanumeric': 0.13535309503051438, 'fraction_numerical': 0.004141238012205754, 'mean_word_length': 2.9731601731601733, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3863079', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1364, 'n_words': 314}