Browse Source

Make the currently-skipped known-failing test actually fail.

Before it was marked as skipped until we could fix it, but if you
forced it to run, it should print out a panic stack trace and then say
PASS. So this makes it actually fail.

Actual fix coming later, now that we have an actual failing list.
Brad Fitzpatrick 11 years ago
parent
commit
996adcbea3
2 changed files with 32 additions and 0 deletions
  1. 12 0
      server.go
  2. 20 0
      server_test.go

+ 12 - 0
server.go

@@ -55,6 +55,7 @@ var responseWriterStatePool = sync.Pool{
 var (
 	testHookOnConn        func()
 	testHookGetServerConn func(*serverConn)
+	testHookOnPanic       func(sc *serverConn, panicVal interface{}) (rePanic bool)
 )
 
 // TODO: finish GOAWAY support. Consider each incoming frame type and
@@ -450,8 +451,19 @@ func (sc *serverConn) stopShutdownTimer() {
 	}
 }
 
+func (sc *serverConn) notePanic() {
+	if testHookOnPanic != nil {
+		if e := recover(); e != nil {
+			if testHookOnPanic(sc, e) {
+				panic(e)
+			}
+		}
+	}
+}
+
 func (sc *serverConn) serve() {
 	sc.serveG.check()
+	defer sc.notePanic()
 	defer sc.conn.Close()
 	defer sc.closeAllStreamsOnConnClose()
 	defer sc.stopShutdownTimer()

+ 20 - 0
server_test.go

@@ -42,6 +42,7 @@ type serverTester struct {
 }
 
 func newServerTester(t *testing.T, handler http.HandlerFunc) *serverTester {
+	testHookOnPanic = nil
 	logBuf := new(bytes.Buffer)
 	ts := httptest.NewUnstartedServer(handler)
 	ConfigureServer(ts.Config, &Server{})
@@ -1793,6 +1794,7 @@ func TestServer_Response_ManyHeaders_With_Continuation(t *testing.T) {
 
 func TestServer_NoCrash_HandlerClose_Then_ClientClose(t *testing.T) {
 	condSkipFailingTest(t)
+
 	testServerResponse(t, func(w http.ResponseWriter, r *http.Request) error {
 		// nothing
 		return nil
@@ -1813,10 +1815,28 @@ func TestServer_NoCrash_HandlerClose_Then_ClientClose(t *testing.T) {
 		// it doesn't crash with an internal invariant panic, like
 		// it did before.
 		st.writeData(1, true, []byte("foo"))
+
+		var (
+			panMu    sync.Mutex
+			panicVal interface{}
+		)
+		testHookOnPanic = func(sc *serverConn, pv interface{}) bool {
+			panMu.Lock()
+			panicVal = pv
+			panMu.Unlock()
+			return true
+		}
+
 		st.cc.Close()
 		select {
 		case <-st.sc.doneServing:
 			// Loop has exited.
+			panMu.Lock()
+			got := panicVal
+			panMu.Unlock()
+			if got != nil {
+				t.Errorf("Got panic: %v", got)
+			}
 		case <-time.After(5 * time.Second):
 			t.Error("timeout")
 		}