Skip to content

Commit

Permalink
Merge pull request #54 from yookoala/maintenance
Browse files Browse the repository at this point in the history
Maintenance
  • Loading branch information
yookoala authored Sep 23, 2020
2 parents 4371ad4 + 18bd0d3 commit 1a6b857
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 98 deletions.
19 changes: 11 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go

dist: trusty
dist: focal

go:
- 1.7.x
Expand All @@ -10,18 +10,20 @@ go:
- 1.11.x
- 1.12.x
- 1.13.x
- tip
- 1.14.x
- 1.15.x
# - tip

addons:
apt:
packages:
- php5-fpm
- php-fpm
- python3
- python3.4-venv
- python3.8-venv

env:
global:
- TEST_PHPFPM_PATH=/usr/sbin/php5-fpm
- TEST_PHPFPM_PATH=/usr/sbin/php-fpm7.4
- GO111MODULE=on

before_script:
Expand All @@ -32,10 +34,11 @@ before_script:
- which pip3 && pip3 --version
- pip3 install -r example/python3/requirements.txt
# for nodejs tests
- curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
- nvm install 8 && npm install -g yarn
- curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.35.3/install.sh | bash
- cd ./example/nodejs && nvm install && npm install -g yarn && cd ../..
- cd ./example/nodejs && yarn install && cd ../..
# for go modules download, if applicable
- go mod download -x || go mod download || go version

script:
- go mod download || go version
- go test -v -race ./...
132 changes: 64 additions & 68 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"bytes"
"context"
"fmt"
"log"
"math/rand"
"net"
"net/http"
"net/http/fcgi"
"net/http/httptest"
"os"
"path/filepath"
"testing"
"time"

Expand All @@ -30,13 +30,48 @@ func newApp(network, address string, fn http.HandlerFunc) (l net.Listener, err e
return
}

// proxy implements Proxy interface
type proxy struct {
network string
address string
// appServer implements Proxy interface
type appServer struct {
listener net.Listener
sock string
}

func testHandlerForCancel(t *testing.T, p *proxy, w http.ResponseWriter, r *http.Request) (errStr string) {
func (p *appServer) Network() string {
return p.listener.Addr().Network()
}

func (p *appServer) Address() string {
return p.listener.Addr().String()
}

func (p *appServer) Close() {
os.Remove(p.sock)
p.listener.Close()
}

func newAppServer(sockName string, fn http.HandlerFunc) (p *appServer, err error) {
// create temporary socket in the testing folder
dir, err := os.Getwd()
if err != nil {
return
}
sock := filepath.Join(dir, sockName)

// create temporary fcgi application server
// that listens to the socket
l, err := newApp("unix", sock, fn)
if err != nil {
return
}

p = &appServer{
listener: l,
sock: sock,
}
return
}

func testHandlerForCancel(t *testing.T, p *appServer, w http.ResponseWriter, r *http.Request) (errStr string) {

NewRequest := func(r *http.Request) (req *gofast.Request) {
var isHTTPS string
Expand Down Expand Up @@ -73,14 +108,14 @@ func testHandlerForCancel(t *testing.T, p *proxy, w http.ResponseWriter, r *http
}

c, err := gofast.SimpleClientFactory(
gofast.SimpleConnFactory(p.network, p.address),
gofast.SimpleConnFactory(p.Network(), p.Address()),
0,
)()
if err != nil {
http.Error(w, "failed to connect to FastCGI application", http.StatusBadGateway)
t.Logf("web server: unable to connect to FastCGI application "+
"(network=%#v, address=%#v, error=%#v)",
p.network, p.address, err.Error())
p.Network(), p.Address(), err.Error())
return
}
innerCtx, cancel := context.WithCancel(r.Context())
Expand All @@ -104,7 +139,7 @@ func testHandlerForCancel(t *testing.T, p *proxy, w http.ResponseWriter, r *http
http.Error(w, "failed to process request", http.StatusInternalServerError)
t.Logf("web server: unable to process request "+
"(network=%#v, address=%#v, error=%#v)",
p.network, p.address, err.Error())
p.Network(), p.Address(), err.Error())
}

errBuffer := new(bytes.Buffer)
Expand All @@ -114,7 +149,7 @@ func testHandlerForCancel(t *testing.T, p *proxy, w http.ResponseWriter, r *http
errStr = errBuffer.String()
t.Logf("web server: error stream from application process "+
"(network=%#v, address=%#v, error=%#v)",
p.network, p.address, errStr)
p.Network(), p.Address(), errStr)
return
}

Expand All @@ -123,16 +158,8 @@ func testHandlerForCancel(t *testing.T, p *proxy, w http.ResponseWriter, r *http

func TestClient_canceled(t *testing.T) {

// create temporary socket in the testing folder
dir, err := os.Getwd()
if err != nil {
t.Errorf("unexpected error: %#v", err.Error())
}
sock := dir + "/client.test.sock"

// create temporary fcgi application server
// that listens to the socket
l, err := newApp("unix", sock, func(w http.ResponseWriter, r *http.Request) {
// create a temp dummy fastcgi application server
p, err := newAppServer("client.test.sock", func(w http.ResponseWriter, r *http.Request) {
t.Logf("accessing FastCGI process")
time.Sleep(10 * time.Second) // mimic long running process
fmt.Fprintf(w, "hello world")
Expand All @@ -141,10 +168,9 @@ func TestClient_canceled(t *testing.T) {
if err != nil {
t.Errorf("unexpected error: %#v", err.Error())
}
defer os.Remove(sock)
defer l.Close()
defer p.Close()

// deine a proxy that access the temp fcgi application server
// deine a appServer that access the temp fcgi application server
w := httptest.NewRecorder()

// request the application server
Expand All @@ -159,31 +185,28 @@ func TestClient_canceled(t *testing.T) {
}

// test error
p := &proxy{l.Addr().Network(), l.Addr().String()}
if want, have := "gofast: timeout or canceled", testHandlerForCancel(t, p, w, r); want != have {
t.Errorf("expected %#v, got %#v", want, have)
}
}

func TestClient_StdErr(t *testing.T) {

// proxy implements Proxy interface
type proxy struct {
network string
address string
}
// create a temp dummy fastcgi application server
p, err := newAppServer("client.test.sock", func(w http.ResponseWriter, r *http.Request) {
t.Logf("accessing FastCGI process")
fmt.Fprintf(w, "hello world")
})
defer p.Close()

// ServeHTTP implements http.Handler
ServeHTTP := func(p *proxy, w http.ResponseWriter, r *http.Request) (errStr string) {
// Do the actual request
doRequest := func(w http.ResponseWriter, r *http.Request) (errStr string) {
c, err := gofast.SimpleClientFactory(
gofast.SimpleConnFactory(p.network, p.address),
gofast.SimpleConnFactory(p.Network(), p.Address()),
0,
)()
if err != nil {
http.Error(w, "failed to connect to FastCGI application", http.StatusBadGateway)
log.Printf("web server: unable to connect to FastCGI application "+
"(network=%#v, address=%#v, error=%#v)",
p.network, p.address, err.Error())
errStr = "web server: unable to connect to FastCGI application: " + err.Error()
return
}
req := gofast.NewRequest(nil)
Expand All @@ -195,47 +218,21 @@ func TestClient_StdErr(t *testing.T) {
// handle the result
resp, err := c.Do(req)
if err != nil {
http.Error(w, "failed to process request", http.StatusInternalServerError)
t.Logf("web server: unable to process request "+
"(network=%#v, address=%#v, error=%#v)",
p.network, p.address, err.Error())
errStr = "web server: unable to connect to process request: " + err.Error()
return
}
errBuffer := new(bytes.Buffer)
resp.WriteTo(w, errBuffer)

if errBuffer.Len() > 0 {
// direct return the error stream
errStr = errBuffer.String()
t.Logf("web server: error stream from application process "+
"(network=%#v, address=%#v, error=%#v)",
p.network, p.address, errStr)
return
}

return
}

// create temporary socket in the testing folder
dir, err := os.Getwd()
if err != nil {
t.Errorf("unexpected error: %#v", err.Error())
}
sock := dir + "/client.test.sock"

// create temporary fcgi application server
// that listens to the socket
fn := func(w http.ResponseWriter, r *http.Request) {
t.Logf("accessing FastCGI process")
fmt.Fprintf(w, "hello world")
}
l, err := newApp("unix", sock, fn)
if err != nil {
t.Errorf("unexpected error: %#v", err.Error())
}
defer os.Remove(sock)
defer l.Close()

// deine a proxy that access the temp fcgi application server
// define an appServer that access the temp fcgi application server
w := httptest.NewRecorder()

// request the application server
Expand All @@ -244,8 +241,8 @@ func TestClient_StdErr(t *testing.T) {
t.Errorf("unexpected error: %#v", err.Error())
}

p := &proxy{l.Addr().Network(), l.Addr().String()}
if want, have := "cgi: no REQUEST_METHOD in environment", ServeHTTP(p, w, r); want != have {
if want, have := "cgi: no REQUEST_METHOD in environment", doRequest(w, r); want != have {
t.Logf("network=%#v, address=%#v", p.Network(), p.Address())
t.Errorf("expected %#v, got %#v", want, have)
}

Expand All @@ -254,5 +251,4 @@ func TestClient_StdErr(t *testing.T) {
if want, have := "", w.Body.String(); want != have {
t.Errorf("expected %#v, got %#v", want, have)
}

}
1 change: 1 addition & 0 deletions example/nodejs/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14
7 changes: 5 additions & 2 deletions example/nodejs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
"bufferlist@>= 0.0.6":
version "0.1.0"
resolved "https://registry.yarnpkg.com/bufferlist/-/bufferlist-0.1.0.tgz#42bef2d89573b40fa1086bb39e0f5310170d1ddd"
integrity sha1-Qr7y2JVztA+hCGuzng9TEBcNHd0=

fastcgi-stream@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fastcgi-stream/-/fastcgi-stream-1.0.0.tgz#a526efb0a56eb23b76248081dd95b61eb5f6685c"
integrity sha1-pSbvsKVusjt2JICB3ZW2HrX2aFw=
dependencies:
bufferlist ">= 0.0.6"

node-fastcgi@^1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/node-fastcgi/-/node-fastcgi-1.3.2.tgz#4246ab2803f344ed7f6dfb3b7e01d4144a73d4dd"
version "1.3.3"
resolved "https://registry.yarnpkg.com/node-fastcgi/-/node-fastcgi-1.3.3.tgz#ba783597ab3c48b005507b74fcde6d0378394384"
integrity sha512-uIfm28LPIg81eD+epaaYTK9motZFxQvTpjtYa0b1lq7U9N+4EDJbPvQpBbVdhmTcQ5PWQgxwFJnp2XLK804NbA==
dependencies:
fastcgi-stream "^1.0.0"
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module github.com/yookoala/gofast

go 1.7

require (
github.com/go-ini/ini v1.38.1
github.com/go-restit/lzjson v0.0.0-20161206095556-efe3c53acc68
github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c // indirect
github.com/jtolds/gls v4.2.1+incompatible // indirect
github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf // indirect
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a // indirect
golang.org/x/tools v0.0.0-20180726210403-bfb5194568d3
gopkg.in/ini.v1 v1.38.2 // indirect
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
github.com/smartystreets/assertions v1.1.1 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
golang.org/x/tools v0.0.0-20200908211811-12e1bf57a112
gopkg.in/ini.v1 v1.38.2
)
46 changes: 34 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
github.com/go-ini/ini v1.38.1 h1:hbtfM8emWUVo9GnXSloXYyFbXxZ+tG6sbepSStoe1FY=
github.com/go-ini/ini v1.38.1/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/go-restit/lzjson v0.0.0-20161206095556-efe3c53acc68 h1:QR2R74UbwMtnEVGVvNfcx6mQmWGgN8abQeXOy92pQIo=
github.com/go-restit/lzjson v0.0.0-20161206095556-efe3c53acc68/go.mod h1:7vXSKQt83WmbPeyVjCfNT9YDJ5BUFmcwFsEjI9SCvYM=
github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c h1:16eHWuMGvCjSfgRJKqIzapE78onvvTbdi1rMkU00lZw=
github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE=
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf h1:6V1qxN6Usn4jy8unvggSJz/NC790tefw8Zdy6OZS5co=
github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a h1:JSvGDIbmil4Ui/dDdFBExb7/cmkNjyX5F97oglmvCDo=
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s=
golang.org/x/tools v0.0.0-20180726210403-bfb5194568d3 h1:OmGWlNEU0GPTUBzTMl9Xbn7v2nOdU64kOQbOrgU97FY=
golang.org/x/tools v0.0.0-20180726210403-bfb5194568d3/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 h1:l5lAOZEym3oK3SQ2HBHWsJUfbNBiTXJDeW2QDxw9AQ0=
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/assertions v1.1.1 h1:T/YLemO5Yp7KPzS+lVtu+WsHn8yoSwTfItdAd1r3cck=
github.com/smartystreets/assertions v1.1.1/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200908211811-12e1bf57a112 h1:DmrRJy1qn9VDMf4+GSpRlwfZ51muIF7r96MFBFP4bPM=
golang.org/x/tools v0.0.0-20200908211811-12e1bf57a112/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/ini.v1 v1.38.2 h1:dGcbywv4RufeGeiMycPT/plKB5FtmLKLnWKwBiLhUA4=
gopkg.in/ini.v1 v1.38.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
2 changes: 1 addition & 1 deletion tools/phpfpm/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"syscall"
"time"

"github.com/go-ini/ini"
"gopkg.in/ini.v1"
)

// Process describes a minimalistic php-fpm config
Expand Down

0 comments on commit 1a6b857

Please sign in to comment.