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

request help: bare net/http pkg would always return "404 Route not found" #1388

Closed
Yiyiyimu opened this issue Jan 28, 2021 · 5 comments
Closed

Comments

@Yiyiyimu
Copy link
Member

The problem is actually about chaos test for apisix, but since it's more about a golang problem and it highly takes e2e test in apisix-dashboard for reference, so I think maybe I'll get more help here.

Background

To test if chaos effect qps of apisix, I try to visit a route in the same frequency, calculate ingress bandwidth per second from prometheus metrics, and then compare before and after the chaos take effect. Ref: apache/apisix#3404

Problem

The current implementation is using httpexpect to visit the route. While it's not satisfactory, since it would print one log each time a request sent so it would print a lot logs and make test log into a mess (commit and messy log). So a bare HTTP get would be better.

However for some reason, using bare net/http pkg to access the route would always return "404 Route not found", although the route is created, accessing the same URL with httpexpect could work(commit). So the next check would fail, getIngressBandwidthPerSecond would return 0 since no request succeeds (see ci error).

It would be great if anyone could help me out 🥺

@Yiyiyimu Yiyiyimu added bug Something isn't working and removed bug Something isn't working labels Jan 28, 2021
@Yiyiyimu Yiyiyimu changed the title Help needed: bare net/http pkg would always return "404 Route not found" request help: bare net/http pkg would always return "404 Route not found" Jan 28, 2021
@starsz
Copy link
Contributor

starsz commented Jan 29, 2021

Hi @Yiyiyimu,

using bare net/http pkg to access the route would always return "404 Route not found", although the route is created, accessing the same URL with httpexpect could work(commit).

  1. How do you use the bare net/http?
  2. If you don't want httpexpect to print a lot logs, you can config the httpexpect.
    See more details: https://pkg.go.dev/github.com/gavv/httpexpect/v2#Config

@nic-chen
Copy link
Member

@Yiyiyimu you could set request.Close = true and have a try again.

@Yiyiyimu
Copy link
Member Author

Yiyiyimu commented Feb 2, 2021

you could set request.Close = true and have a try again.

Thanks for the suggestions @nic-chen !! But it seems still not works...

I just found out dashboard e2e test has almost the same function, I'll have a test to see if it works

@Yiyiyimu
Copy link
Member Author

Yiyiyimu commented Feb 2, 2021

Thanks for the suggestions @starsz!

  1. It's in that commit, and would be something like
func getWithoutTest(g *WithT, path string, headers map[string]string) string {
	client := &http.Client{}
	url := host + path

	req, err := http.NewRequest(http.MethodGet, url, nil)
	g.Expect(err).To(BeNil())
	for key, value := range headers {
		req.Header.Add(key, value)
	}

	resp, err := client.Do(req)
	g.Expect(err).To(BeNil())
	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	g.Expect(err).To(BeNil())

	return string(body)
}
  1. It seems the default printer is already the most simple one - CompactPrinter (see code). So there seems no better option for using httpexpect 😿

@Yiyiyimu
Copy link
Member Author

Yiyiyimu commented Feb 2, 2021

It seems the default printer is already the most simple one - CompactPrinter (see code). So there seems no better option for using httpexpect 😿

Sorry I made a mistake, Printer is an interface so I could implement a simpler one.


Done. Now it print no logs at all. Thanks for the suggestions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants