File: leaktest_utils_test.go

package info (click to toggle)
golang-github-fortytw2-leaktest 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 88 kB
  • sloc: makefile: 2
file content (30 lines) | stat: -rw-r--r-- 606 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package leaktest

import (
	"context"
	"net/http"
	"net/http/httptest"
	"time"
)

func index() http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusOK)
	})
}

func startKeepAliveEnabledServer(ctx context.Context) *httptest.Server {
	server := httptest.NewUnstartedServer(index())
	server.Config.ReadTimeout = 5 * time.Second
	server.Config.WriteTimeout = 10 * time.Second
	server.Config.IdleTimeout = 15 * time.Second
	server.Config.SetKeepAlivesEnabled(true)

	server.Start()
	go func() {
		<-ctx.Done()
		server.Close()
	}()

	return server
}