@@ -677,157 +677,6 @@ func AssertIfPipeReadable(t *testing.T, pipe io.ReadCloser) {
677677 }
678678}
679679
680- func TestMultipleStreamsWithDictionaries (t * testing.T ) {
681- l := zerolog .Nop ()
682-
683- for q := CompressionNone ; q <= CompressionMax ; q ++ {
684- htmlBody := `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"` +
685- `"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">` +
686- `<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">` +
687- `<head>` +
688- ` <title>Your page title here</title>` +
689- `</head>` +
690- `<body>` +
691- `<h1>Your major heading here</h1>` +
692- `<p>` +
693- `This is a regular text paragraph.` +
694- `</p>` +
695- `<ul>` +
696- ` <li>` +
697- ` First bullet of a bullet list.` +
698- ` </li>` +
699- ` <li>` +
700- ` This is the <em>second</em> bullet.` +
701- ` </li>` +
702- `</ul>` +
703- `</body>` +
704- `</html>`
705-
706- f := MuxedStreamFunc (func (stream * MuxedStream ) error {
707- var contentType string
708- var pathHeader Header
709-
710- for _ , h := range stream .Headers {
711- if h .Name == ":path" {
712- pathHeader = h
713- break
714- }
715- }
716-
717- if pathHeader .Name != ":path" {
718- panic ("Couldn't find :path header in test" )
719- }
720-
721- if strings .Contains (pathHeader .Value , "html" ) {
722- contentType = "text/html; charset=utf-8"
723- } else if strings .Contains (pathHeader .Value , "js" ) {
724- contentType = "application/javascript"
725- } else if strings .Contains (pathHeader .Value , "css" ) {
726- contentType = "text/css"
727- } else {
728- contentType = "img/gif"
729- }
730-
731- _ = stream .WriteHeaders ([]Header {
732- {Name : "content-type" , Value : contentType },
733- })
734- _ , _ = stream .Write ([]byte (strings .Replace (htmlBody , "paragraph" , pathHeader .Value , 1 ) + stream .Headers [5 ].Value ))
735-
736- return nil
737- })
738- muxPair := NewCompressedMuxerPair (t , fmt .Sprintf ("%s_%d" , t .Name (), q ), q , f )
739- muxPair .Serve (t )
740-
741- var wg sync.WaitGroup
742-
743- paths := []string {
744- "/html1" ,
745- "/html2?sa:ds" ,
746- "/html3" ,
747- "/css1" ,
748- "/html1" ,
749- "/html2?sa:ds" ,
750- "/html3" ,
751- "/css1" ,
752- "/css2" ,
753- "/css3" ,
754- "/js" ,
755- "/js" ,
756- "/js" ,
757- "/js2" ,
758- "/img2" ,
759- "/html1" ,
760- "/html2?sa:ds" ,
761- "/html3" ,
762- "/css1" ,
763- "/css2" ,
764- "/css3" ,
765- "/js" ,
766- "/js" ,
767- "/js" ,
768- "/js2" ,
769- "/img1" ,
770- }
771-
772- wg .Add (len (paths ))
773- errorsC := make (chan error , len (paths ))
774-
775- for i , s := range paths {
776- go func (index int , path string ) {
777- defer wg .Done ()
778- stream , err := muxPair .OpenEdgeMuxStream (
779- []Header {
780- {Name : ":method" , Value : "GET" },
781- {Name : ":scheme" , Value : "https" },
782- {Name : ":authority" , Value : "tunnel.otterlyadorable.co.uk" },
783- {Name : ":path" , Value : path },
784- {Name : "cf-ray" , Value : "378948953f044408-SFO-DOG" },
785- {Name : "idx" , Value : strconv .Itoa (index )},
786- {Name : "accept-encoding" , Value : "gzip, br" },
787- },
788- nil ,
789- )
790- if err != nil {
791- errorsC <- fmt .Errorf ("error in OpenStream: %v" , err )
792- return
793- }
794-
795- expectBody := strings .Replace (htmlBody , "paragraph" , path , 1 ) + strconv .Itoa (index )
796- responseBody := make ([]byte , len (expectBody )* 2 )
797- n , err := stream .Read (responseBody )
798- if err != nil {
799- errorsC <- fmt .Errorf ("stream %d error from (*MuxedStream).Read: %s" , stream .streamID , err )
800- return
801- }
802- if n != len (expectBody ) {
803- errorsC <- fmt .Errorf ("stream %d expected response body to have %d bytes, got %d" , stream .streamID , len (expectBody ), n )
804- return
805- }
806- if string (responseBody [:n ]) != expectBody {
807- errorsC <- fmt .Errorf ("stream %d expected response body %s, got %s" , stream .streamID , expectBody , responseBody [:n ])
808- return
809- }
810- }(i , s )
811- }
812-
813- wg .Wait ()
814- close (errorsC )
815- testFail := false
816- for err := range errorsC {
817- testFail = true
818- l .Error ().Msgf ("%s" , err )
819- }
820- if testFail {
821- t .Fatalf ("TestMultipleStreams failed" )
822- }
823-
824- originMuxMetrics := muxPair .OriginMux .Metrics ()
825- if q > CompressionNone && originMuxMetrics .CompBytesBefore .Value () <= 10 * originMuxMetrics .CompBytesAfter .Value () {
826- t .Fatalf ("Cross-stream compression is expected to give a better compression ratio" )
827- }
828- }
829- }
830-
831680func sampleSiteHandler (files map [string ][]byte ) MuxedStreamFunc {
832681 return func (stream * MuxedStream ) error {
833682 var contentType string
@@ -914,82 +763,6 @@ func loadSampleFiles(paths []string) (map[string][]byte, error) {
914763 return files , nil
915764}
916765
917- func TestSampleSiteWithDictionaries (t * testing.T ) {
918- paths := []string {
919- "./sample/index.html" ,
920- "./sample/index2.html" ,
921- "./sample/index1.html" ,
922- "./sample/ghost-url.min.js" ,
923- "./sample/jquery.fitvids.js" ,
924- "./sample/index1.html" ,
925- "./sample/index2.html" ,
926- "./sample/index.html" ,
927- }
928- files , err := loadSampleFiles (paths )
929- assert .NoError (t , err )
930-
931- for q := CompressionNone ; q <= CompressionMax ; q ++ {
932- muxPair := NewCompressedMuxerPair (t , fmt .Sprintf ("%s_%d" , t .Name (), q ), q , sampleSiteHandler (files ))
933- muxPair .Serve (t )
934-
935- var wg sync.WaitGroup
936- errC := make (chan error , len (paths ))
937-
938- wg .Add (len (paths ))
939- for _ , s := range paths {
940- go func (path string ) {
941- defer wg .Done ()
942- errC <- sampleSiteTest (muxPair , path , files )
943- }(s )
944- }
945-
946- wg .Wait ()
947- close (errC )
948-
949- for err := range errC {
950- assert .NoError (t , err )
951- }
952-
953- originMuxMetrics := muxPair .OriginMux .Metrics ()
954- if q > CompressionNone && originMuxMetrics .CompBytesBefore .Value () <= 10 * originMuxMetrics .CompBytesAfter .Value () {
955- t .Fatalf ("Cross-stream compression is expected to give a better compression ratio" )
956- }
957- }
958- }
959-
960- func TestLongSiteWithDictionaries (t * testing.T ) {
961- paths := []string {
962- "./sample/index.html" ,
963- "./sample/index1.html" ,
964- "./sample/index2.html" ,
965- "./sample/ghost-url.min.js" ,
966- "./sample/jquery.fitvids.js" ,
967- }
968- files , err := loadSampleFiles (paths )
969- assert .NoError (t , err )
970- for q := CompressionNone ; q <= CompressionMedium ; q ++ {
971- muxPair := NewCompressedMuxerPair (t , fmt .Sprintf ("%s_%d" , t .Name (), q ), q , sampleSiteHandler (files ))
972- muxPair .Serve (t )
973-
974- rand .Seed (time .Now ().Unix ())
975-
976- tstLen := 500
977- errGroup , _ := errgroup .WithContext (context .Background ())
978- for i := 0 ; i < tstLen ; i ++ {
979- errGroup .Go (func () error {
980- path := paths [rand .Int ()% len (paths )]
981- return sampleSiteTest (muxPair , path , files )
982- })
983- }
984- assert .NoError (t , errGroup .Wait ())
985-
986- originMuxMetrics := muxPair .OriginMux .Metrics ()
987- if q > CompressionNone && originMuxMetrics .CompBytesBefore .Value () <= 10 * originMuxMetrics .CompBytesAfter .Value () {
988- t .Fatalf ("Cross-stream compression is expected to give a better compression ratio" )
989- }
990- }
991- }
992-
993766func BenchmarkOpenStream (b * testing.B ) {
994767 const streams = 5000
995768 for i := 0 ; i < b .N ; i ++ {
0 commit comments