Merge pull request #23151 from AkihiroSuda/fix23012PkgAuth

Fix racy tests in pkg/authorization
This commit is contained in:
Brian Goff 2016-06-01 20:45:54 -04:00
commit 83be58f17e

View file

@ -28,7 +28,7 @@ const pluginAddress = "authzplugin.sock"
func TestAuthZRequestPluginError(t *testing.T) { func TestAuthZRequestPluginError(t *testing.T) {
server := authZPluginTestServer{t: t} server := authZPluginTestServer{t: t}
go server.start() server.start()
defer server.stop() defer server.stop()
authZPlugin := createTestPlugin(t) authZPlugin := createTestPlugin(t)
@ -59,7 +59,7 @@ func TestAuthZRequestPluginError(t *testing.T) {
func TestAuthZRequestPlugin(t *testing.T) { func TestAuthZRequestPlugin(t *testing.T) {
server := authZPluginTestServer{t: t} server := authZPluginTestServer{t: t}
go server.start() server.start()
defer server.stop() defer server.stop()
authZPlugin := createTestPlugin(t) authZPlugin := createTestPlugin(t)
@ -91,7 +91,7 @@ func TestAuthZRequestPlugin(t *testing.T) {
func TestAuthZResponsePlugin(t *testing.T) { func TestAuthZResponsePlugin(t *testing.T) {
server := authZPluginTestServer{t: t} server := authZPluginTestServer{t: t}
go server.start() server.start()
defer server.stop() defer server.stop()
authZPlugin := createTestPlugin(t) authZPlugin := createTestPlugin(t)
@ -223,6 +223,7 @@ type authZPluginTestServer struct {
recordedRequest Request recordedRequest Request
// response stores the response sent from the plugin to the daemon // response stores the response sent from the plugin to the daemon
replayResponse Response replayResponse Response
server *httptest.Server
} }
// start starts the test server that implements the plugin // start starts the test server that implements the plugin
@ -234,12 +235,19 @@ func (t *authZPluginTestServer) start() {
r.HandleFunc("/Plugin.Activate", t.activate) r.HandleFunc("/Plugin.Activate", t.activate)
r.HandleFunc("/"+AuthZApiRequest, t.auth) r.HandleFunc("/"+AuthZApiRequest, t.auth)
r.HandleFunc("/"+AuthZApiResponse, t.auth) r.HandleFunc("/"+AuthZApiResponse, t.auth)
server := http.Server{Handler: r, Addr: pluginAddress} t.server = &httptest.Server{
server.Serve(l) Listener: l,
Config: &http.Server{
Handler: r,
Addr: pluginAddress,
},
}
t.server.Start()
} }
// stop stops the test server that implements the plugin // stop stops the test server that implements the plugin
func (t *authZPluginTestServer) stop() { func (t *authZPluginTestServer) stop() {
t.server.Close()
os.Remove(pluginAddress) os.Remove(pluginAddress)
if t.listener != nil { if t.listener != nil {
t.listener.Close() t.listener.Close()