Browse Source

Separate Go tests in travis, easyjson in Go/fasthttp (#4529)

* deleted some go test; updated go vet to 1.12 in fasthttp, go-std, iris; added evio tests

* add sync.Pool to go-std

* test sync.Pool in DBHandler

* add some sync.Pool to go-std

* fixed fortunes test in go-std

* before merge

* added sync.Pool in go-std mysql and mgo drivers

* Separate Go tests in travis

* fix go ver in Go/iris

* fix num loops in Go/evio

* group Go tests

* remove redundant args

* add easyjson support to Go/fasthttp
chunariov 6 years ago
parent
commit
42b9472356

+ 100 - 104
.travis.yml

@@ -13,111 +13,108 @@ services:
 
 env:
   matrix:
-     - "TESTLANG=C"
-     - "TESTLANG=CSharp"
-     - 'TESTDIR="C++/cppcms C++/cpoll_cppsp C++/poco"'
-     - "TESTDIR=C++/ffead-cpp"
-     - "TESTDIR=C++/cutelyst"
-     - "TESTDIR=C++/libhttpserver"
-     - "TESTDIR=C++/silicon"
-     - "TESTDIR=C++/treefrog"
-     - "TESTDIR=C++/ulib"
-     - "TESTDIR=C++/wt"
-     - "TESTDIR=C++/drogon"
-     - "TESTLANG=Clojure"
-     - "TESTLANG=Crystal"
-     - "TESTLANG=D"
-     - "TESTLANG=Dart"
-     - "TESTLANG=Elixir"
-     - "TESTLANG=Erlang"
-     - "TESTLANG=FSharp"
-     - "TESTLANG=Go"
-     - "TESTLANG=Groovy"
-     - "TESTDIR=Haskell/snap"
-     - "TESTDIR=Haskell/wai"
-     - "TESTDIR=Haskell/yesod"
-     - "TESTDIR=Haskell/servant"
-     - "TESTDIR=Haskell/spock"
-     - "TESTDIR=Java/act"
-     - "TESTDIR=Java/activeweb"
-     - "TESTDIR=Java/armeria"
-     - "TESTDIR=Java/baratine"
-     - "TESTDIR=Java/baseio"
-     - "TESTDIR=Java/bayou"
-     - "TESTDIR=Java/blade"
-     - "TESTDIR=Java/comsat"
-     - "TESTDIR=Java/curacao"
-     - "TESTDIR=Java/dropwizard"
-     - "TESTDIR=Java/gemini"
-     - "TESTDIR=Java/greenlightning"
-     - "TESTDIR=Java/grizzly"
-     - "TESTDIR=Java/grizzly-jersey"
-     - "TESTDIR=Java/helidon"
-     - "TESTDIR=Java/httpserver"
-     - "TESTDIR=Java/jawn"
-     - "TESTDIR=Java/javalin"
-     - "TESTDIR=Java/jetty"
-     - "TESTDIR=Java/jlhttp"
-     - "TESTDIR=Java/jooby"
-     - "TESTDIR=Java/jooby2"
-     - "TESTDIR=Java/light-java"
-     - "TESTDIR=Java/micronaut"
-     - "TESTDIR=Java/minijax"
-     - "TESTDIR=Java/nanohttpd"
-     - "TESTDIR=Java/netty"
-     - "TESTDIR=Java/ninja-standalone"
-     - "TESTDIR=Java/officefloor"
-     - "TESTDIR=Java/play1"
-     - "TESTDIR=Java/play2-java"
-     - "TESTDIR=Java/proteus"
-     - "TESTDIR=Java/rapidoid"
-     - "TESTDIR=Java/ratpack"
-     - "TESTDIR=Java/redkale"
-     - "TESTDIR=Java/restexpress"
-     - "TESTDIR=Java/revenj-jvm"
-     - "TESTDIR=Java/servlet"
-     - "TESTDIR=Java/servlet3"
-     - "TESTDIR=Java/smart-socket"
-     - "TESTDIR=Java/spark"
-     - "TESTDIR=Java/spring"
-     - "TESTDIR=Java/spring-webflux"
-     - "TESTDIR=Java/tapestry"
-     - "TESTDIR=Java/t-io"
-     - "TESTDIR=Java/undertow"
-     - "TESTDIR=Java/undertow-jersey"
-     - "TESTDIR=Java/vertx"
-     - "TESTDIR=Java/voovan"
-     - "TESTDIR=Java/vertx-web"
-     - "TESTDIR=Java/wicket"
-     - "TESTDIR=Java/wildfly-ee"
-     - "TESTDIR=Java/wizzardo-http"
-     - "TESTLANG=JavaScript"
-     - "TESTLANG=Kotlin"
-     - "TESTLANG=Lisp"
-     - "TESTLANG=Lua"
-     - "TESTLANG=Nim"
-     - "TESTLANG=Perl"
-     - 'TESTDIR="PHP/php"'
-     - 'TESTDIR="PHP/cakephp PHP/codeigniter PHP/fat-free PHP/fuel PHP/kumbiaphp PHP/laravel PHP/limonade PHP/lithium PHP/lumen PHP/phpixie PHP/slim PHP/symfony PHP/yii2 PHP/zend"'
-     - 'TESTDIR="PHP/amp PHP/hamlet PHP/hhvm PHP/peachpie PHP/swoole PHP/workerman PHP/phalcon"'
-     - 'TESTDIR="Python/aiohttp Python/api_hour Python/blacksheep Python/bottle Python/cherrypy Python/django Python/eve Python/falcon Python/fastapi Python/flask"'
-     - 'TESTDIR="Python/hug Python/japronto Python/klein Python/morepath Python/pyramid Python/quart Python/responder Python/sanic Python/spyne Python/starlette"'
-     - 'TESTDIR="Python/tornado Python/turbogears Python/uvicorn Python/uwsgi Python/vibora Python/web2py Python/webware Python/weppy Python/wsgi"'
-     - 'TESTDIR="Ruby/grape Ruby/h2o_mruby Ruby/hanami Ruby/padrino Ruby/rack Ruby/rack-sequel"'
-     - 'TESTDIR="Ruby/rails Ruby/roda-sequel Ruby/sinatra Ruby/sinatra-sequel"'
-     - 'TESTDIR="Rust/actix Rust/gotham Rust/hyper Rust/iron Rust/saphir"'
-     - 'TESTDIR="Rust/may-minihttp Rust/nickel Rust/rocket"'
-     - 'TESTDIR="Rust/rouille Rust/thruster Rust/tokio-minihttp"'
-     - "TESTLANG=Scala"
-     - "TESTLANG=Swift"
-     - "TESTLANG=TypeScript"
-     - "TESTLANG=Ur"
-     - "TESTLANG=Vala"
-     - "TESTLANG=VB"
-
+    - "TESTLANG=C"
+    - "TESTLANG=CSharp"
+    - 'TESTDIR="C++/cppcms C++/cpoll_cppsp C++/poco"'
+    - "TESTDIR=C++/ffead-cpp"
+    - "TESTDIR=C++/cutelyst"
+    - "TESTDIR=C++/libhttpserver"
+    - "TESTDIR=C++/silicon"
+    - "TESTDIR=C++/treefrog"
+    - "TESTDIR=C++/ulib"
+    - "TESTDIR=C++/wt"
+    - "TESTDIR=C++/drogon"
+    - "TESTLANG=Clojure"
+    - "TESTLANG=Crystal"
+    - "TESTLANG=D"
+    - "TESTLANG=Dart"
+    - "TESTLANG=Elixir"
+    - "TESTLANG=Erlang"
+    - "TESTLANG=FSharp"
+    - 'TESTDIR="GO/aah GO/chi GO/falcore GO/gin GO/goji GO/kami GO/martini GO/revel GO/webgo"'
+    - 'TESTDIR="GO/beego GO/echo"'
+    - 'TESTDIR="GO/evio GO/fasthttp GO/go-std GO/iris"'
+    - "TESTLANG=Groovy"
+    - "TESTDIR=Haskell/snap"
+    - "TESTDIR=Haskell/wai"
+    - "TESTDIR=Haskell/yesod"
+    - "TESTDIR=Haskell/servant"
+    - "TESTDIR=Haskell/spock"
+    - "TESTDIR=Java/act"
+    - "TESTDIR=Java/activeweb"
+    - "TESTDIR=Java/armeria"
+    - "TESTDIR=Java/baratine"
+    - "TESTDIR=Java/baseio"
+    - "TESTDIR=Java/bayou"
+    - "TESTDIR=Java/blade"
+    - "TESTDIR=Java/comsat"
+    - "TESTDIR=Java/curacao"
+    - "TESTDIR=Java/dropwizard"
+    - "TESTDIR=Java/gemini"
+    - "TESTDIR=Java/greenlightning"
+    - "TESTDIR=Java/grizzly"
+    - "TESTDIR=Java/grizzly-jersey"
+    - "TESTDIR=Java/helidon"
+    - "TESTDIR=Java/httpserver"
+    - "TESTDIR=Java/jawn"
+    - "TESTDIR=Java/javalin"
+    - "TESTDIR=Java/jetty"
+    - "TESTDIR=Java/jlhttp"
+    - "TESTDIR=Java/jooby"
+    - "TESTDIR=Java/jooby2"
+    - "TESTDIR=Java/light-java"
+    - "TESTDIR=Java/micronaut"
+    - "TESTDIR=Java/minijax"
+    - "TESTDIR=Java/nanohttpd"
+    - "TESTDIR=Java/netty"
+    - "TESTDIR=Java/ninja-standalone"
+    - "TESTDIR=Java/officefloor"
+    - "TESTDIR=Java/play1"
+    - "TESTDIR=Java/play2-java"
+    - "TESTDIR=Java/proteus"
+    - "TESTDIR=Java/rapidoid"
+    - "TESTDIR=Java/ratpack"
+    - "TESTDIR=Java/redkale"
+    - "TESTDIR=Java/restexpress"
+    - "TESTDIR=Java/revenj-jvm"
+    - "TESTDIR=Java/servlet"
+    - "TESTDIR=Java/servlet3"
+    - "TESTDIR=Java/smart-socket"
+    - "TESTDIR=Java/spark"
+    - "TESTDIR=Java/spring"
+    - "TESTDIR=Java/spring-webflux"
+    - "TESTDIR=Java/tapestry"
+    - "TESTDIR=Java/t-io"
+    - "TESTDIR=Java/undertow"
+    - "TESTDIR=Java/undertow-jersey"
+    - "TESTDIR=Java/vertx"
+    - "TESTDIR=Java/voovan"
+    - "TESTDIR=Java/vertx-web"
+    - "TESTDIR=Java/wicket"
+    - "TESTDIR=Java/wildfly-ee"
+    - "TESTDIR=Java/wizzardo-http"
+    - "TESTLANG=JavaScript"
+    - "TESTLANG=Kotlin"
+    - "TESTLANG=Lisp"
+    - "TESTLANG=Lua"
+    - "TESTLANG=Nim"
+    - "TESTLANG=Perl"
+    - 'TESTDIR="PHP/php"'
+    - 'TESTDIR="PHP/cakephp PHP/codeigniter PHP/fat-free PHP/fuel PHP/kumbiaphp PHP/laravel PHP/limonade PHP/lithium PHP/lumen PHP/phpixie PHP/slim PHP/symfony PHP/yii2 PHP/zend"'
+    - 'TESTDIR="PHP/amp PHP/hamlet PHP/hhvm PHP/peachpie PHP/swoole PHP/workerman PHP/phalcon"'
+    - "TESTLANG=Python"
+    - "TESTLANG=Ruby"
+    - 'TESTDIR="Rust/actix Rust/gotham Rust/hyper Rust/iron Rust/saphir"'
+    - 'TESTDIR="Rust/may-minihttp Rust/nickel Rust/rocket"'
+    - 'TESTDIR="Rust/rouille Rust/thruster Rust/tokio-minihttp"'
+    - "TESTLANG=Scala"
+    - "TESTLANG=Swift"
+    - "TESTLANG=TypeScript"
+    - "TESTLANG=Ur"
+    - "TESTLANG=Vala"
+    - "TESTLANG=VB"
 
 before_script:
-
   # Runs travis_diff, printing the output to the terminal, and searches for travis-diff-continue
   # to determine if the suite should be installed and the current $TESTDIR test should run.
   - export RUN_TESTS=`./toolset/travis/travis_diff.py | tee /dev/tty | grep -oP "travis-run-tests \K(.*)"`
@@ -129,7 +126,6 @@ before_script:
   - sudo service postgresql stop
 
 script:
-
   # run-ci.py runs the diffing to see if travis needs to test this framework. Ideally/eventually,
   # we'd like to try and do the diffing before travis_clean & setup.
   # This will run the tests exactly as you would in your own vm:

+ 1 - 0
frameworks/Go/fasthttp/fasthttp-postgresql-prefork.dockerfile

@@ -15,6 +15,7 @@ RUN go get -u github.com/mailru/easyjson/...
 
 RUN rm -f ./server-postgresql
 RUN go generate templates
+RUN easyjson -all src/common/common.go
 RUN go build -gcflags='-l=4' server-postgresql
 
 CMD ./server-postgresql -prefork

+ 1 - 0
frameworks/Go/fasthttp/fasthttp-postgresql.dockerfile

@@ -15,6 +15,7 @@ RUN go get -u github.com/mailru/easyjson/...
 
 RUN rm -f ./server-postgresql
 RUN go generate templates
+RUN easyjson -all src/common/common.go
 RUN go build -gcflags='-l=4' server-postgresql
 
 CMD ./server-postgresql

+ 1 - 0
frameworks/Go/fasthttp/fasthttp-prefork.dockerfile

@@ -15,6 +15,7 @@ RUN go get -u github.com/mailru/easyjson/...
 
 RUN rm -f ./server-mysql
 RUN go generate templates
+RUN easyjson -all src/common/common.go
 RUN go build -gcflags='-l=4' server-mysql
 
 CMD ./server-mysql -prefork

+ 1 - 0
frameworks/Go/fasthttp/fasthttp.dockerfile

@@ -15,6 +15,7 @@ RUN go get -u github.com/mailru/easyjson/...
 
 RUN rm -f ./server-mysql
 RUN go generate templates
+RUN easyjson -all src/common/common.go
 RUN go build -gcflags='-l=4' server-mysql
 
 CMD ./server-mysql

+ 10 - 2
frameworks/Go/fasthttp/src/common/common.go

@@ -24,11 +24,19 @@ type World struct {
 	RandomNumber int32 `json:"randomNumber"`
 }
 
+type Worlds []World
+
 func JSONHandler(ctx *fasthttp.RequestCtx) {
 	r := jsonResponsePool.Get().(*JSONResponse)
+	defer jsonResponsePool.Put(r)
 	r.Message = "Hello, World!"
-	JSONMarshal(ctx, r)
-	jsonResponsePool.Put(r)
+	rb, err := r.MarshalJSON()
+	if err != nil {
+		log.Println(err)
+		return
+	}
+	ctx.SetContentType("application/json")
+	ctx.Write(rb)
 }
 
 var jsonResponsePool = &sync.Pool{

+ 1 - 0
frameworks/Go/fasthttp/src/common/common_easyjson.go

@@ -4,6 +4,7 @@ package common
 
 import (
 	json "encoding/json"
+
 	easyjson "github.com/mailru/easyjson"
 	jlexer "github.com/mailru/easyjson/jlexer"
 	jwriter "github.com/mailru/easyjson/jwriter"

+ 21 - 3
frameworks/Go/fasthttp/src/server-mysql/server.go

@@ -86,7 +86,13 @@ func mainHandler(ctx *fasthttp.RequestCtx) {
 func dbHandler(ctx *fasthttp.RequestCtx) {
 	var w common.World
 	fetchRandomWorld(&w)
-	common.JSONMarshal(ctx, &w)
+	wb, err := w.MarshalJSON()
+	if err != nil {
+		log.Println(err)
+		return
+	}
+	ctx.SetContentType("application/json")
+	ctx.Write(wb)
 }
 
 func queriesHandler(ctx *fasthttp.RequestCtx) {
@@ -95,7 +101,13 @@ func queriesHandler(ctx *fasthttp.RequestCtx) {
 	for i := 0; i < n; i++ {
 		fetchRandomWorld(&worlds[i])
 	}
-	common.JSONMarshal(ctx, worlds)
+	wb, err := common.Worlds(worlds).MarshalJSON()
+	if err != nil {
+		log.Println(err)
+		return
+	}
+	ctx.SetContentType("application/json")
+	ctx.Write(wb)
 }
 
 func fortuneHandler(ctx *fasthttp.RequestCtx) {
@@ -149,7 +161,13 @@ func updateHandler(ctx *fasthttp.RequestCtx) {
 		log.Fatalf("Error when commiting world rows: %s", err)
 	}
 
-	common.JSONMarshal(ctx, worlds)
+	wb, err := common.Worlds(worlds).MarshalJSON()
+	if err != nil {
+		log.Println(err)
+		return
+	}
+	ctx.SetContentType("application/json")
+	ctx.Write(wb)
 }
 
 func fetchRandomWorld(w *common.World) {

+ 21 - 3
frameworks/Go/fasthttp/src/server-postgresql/server.go

@@ -77,7 +77,13 @@ func mainHandler(ctx *fasthttp.RequestCtx) {
 func dbHandler(ctx *fasthttp.RequestCtx) {
 	var w common.World
 	fetchRandomWorld(&w)
-	common.JSONMarshal(ctx, &w)
+	wb, err := w.MarshalJSON()
+	if err != nil {
+		log.Println(err)
+		return
+	}
+	ctx.SetContentType("application/json")
+	ctx.Write(wb)
 }
 
 func queriesHandler(ctx *fasthttp.RequestCtx) {
@@ -86,7 +92,13 @@ func queriesHandler(ctx *fasthttp.RequestCtx) {
 	for i := 0; i < n; i++ {
 		fetchRandomWorld(&worlds[i])
 	}
-	common.JSONMarshal(ctx, worlds)
+	wb, err := common.Worlds(worlds).MarshalJSON()
+	if err != nil {
+		log.Println(err)
+		return
+	}
+	ctx.SetContentType("application/json")
+	ctx.Write(wb)
 }
 
 func fortuneHandler(ctx *fasthttp.RequestCtx) {
@@ -140,7 +152,13 @@ func updateHandler(ctx *fasthttp.RequestCtx) {
 		log.Fatalf("Error when commiting world rows: %s", err)
 	}
 
-	common.JSONMarshal(ctx, worlds)
+	wb, err := common.Worlds(worlds).MarshalJSON()
+	if err != nil {
+		log.Println(err)
+		return
+	}
+	ctx.SetContentType("application/json")
+	ctx.Write(wb)
 }
 
 func fetchRandomWorld(w *common.World) {

+ 36 - 1
frameworks/Go/go-std/src/handlers/handlers.go

@@ -163,6 +163,41 @@ func FortuneQuickHandlerPool(db storage.DB) func(w http.ResponseWriter, r *http.
 	}
 }
 
+// UpdateHandlerChan . Test 5: Database updates
+func UpdateHandlerChan(db storage.DB) func(w http.ResponseWriter, r *http.Request) {
+	return func(w http.ResponseWriter, r *http.Request) {
+		queries := queriesParam(r)
+		var err error
+
+		world := storage.WorldPool.Get().(*storage.World)
+		in := make(chan *storage.World, queries)
+		go func() {
+			for i := 0; i < queries; i++ {
+				if err = db.GetOneRandomWorld(world); err != nil {
+					log.Println(err)
+					continue
+				}
+				in <- world
+			}
+			close(in)
+		}()
+
+		// worlds := make([]storage.World, queries)
+		worlds := storage.WorldsPool.Get().([]storage.World)[:queries]
+		if err = db.UpdateWorldsChan(in, worlds); err != nil {
+			log.Println(err)
+			return
+		}
+
+		w.Header().Set("Server", "Go")
+		w.Header().Set("Content-Type", "application/json")
+		json.NewEncoder(w).Encode(worlds)
+
+		worlds = worlds[:0]
+		storage.WorldsPool.Put(worlds)
+	}
+}
+
 // UpdateHandler . Test 5: Database updates
 func UpdateHandler(db storage.DB) func(w http.ResponseWriter, r *http.Request) {
 	return func(w http.ResponseWriter, r *http.Request) {
@@ -179,7 +214,7 @@ func UpdateHandler(db storage.DB) func(w http.ResponseWriter, r *http.Request) {
 			}
 		}
 
-		if err = db.UpdateWorlds(worlds, queries); err != nil {
+		if err = db.UpdateWorlds(worlds); err != nil {
 			log.Println(err)
 			return
 		}

+ 1 - 1
frameworks/Go/go-std/src/handlers/handlers_easyjson.go

@@ -92,7 +92,7 @@ func UpdateHandlerEasyJSON(db storage.DB) func(w http.ResponseWriter, r *http.Re
 		for i := 0; i < queries; i++ {
 			_ = db.GetOneRandomWorld(&worlds[i])
 		}
-		if err := db.UpdateWorlds(worlds, queries); err != nil {
+		if err := db.UpdateWorlds(worlds); err != nil {
 			log.Println(err)
 			return
 		}

+ 1 - 1
frameworks/Go/go-std/src/main.go

@@ -67,7 +67,7 @@ func main() {
 		} else {
 			http.HandleFunc("/db", handlers.DBHandler(db))
 			http.HandleFunc("/queries", handlers.QueriesHandler(db))
-			http.HandleFunc("/update", handlers.UpdateHandler(db))
+			http.HandleFunc("/update", handlers.UpdateHandlerChan(db))
 		}
 	}
 

+ 1 - 2
frameworks/Go/go-std/src/storage/db.go

@@ -28,8 +28,7 @@ const (
 type DB interface {
 	// GetOneRandomWorld() (World, error)
 	GetOneRandomWorld(*World) error
-	// UpdateWorlds([]World, int) error
-	UpdateWorlds([]World, int) error
+	UpdateWorlds([]World) error
 	GetFortunes() ([]templates.Fortune, error)
 	GetFortunesPool() ([]templates.Fortune, error)
 	Close()

+ 1 - 1
frameworks/Go/go-std/src/storage/mgo.go

@@ -50,7 +50,7 @@ func (mongo Mongo) GetOneRandomWorld(w *World) error {
 }
 
 // UpdateRandomWorlds updates some number of worlds entries, passed as arg
-func (mongo Mongo) UpdateWorlds(selectedWorlds []World, queries int) error {
+func (mongo Mongo) UpdateWorlds(selectedWorlds []World) error {
 	for _, selectedWorld := range selectedWorlds {
 		selectedWorld.RandomNumber = rand.Intn(worldsCount) + 1
 		if err := mongo.worlds.Update(

+ 1 - 1
frameworks/Go/go-std/src/storage/mysql.go

@@ -66,7 +66,7 @@ func (mysql MySQL) GetOneRandomWorld(w *World) error {
 }
 
 // UpdateWorlds updates some number of worlds entries, passed as arg
-func (mysql MySQL) UpdateWorlds(selectedWorlds []World, queries int) error {
+func (mysql MySQL) UpdateWorlds(selectedWorlds []World) error {
 	// against deadlocks
 	sort.Slice(selectedWorlds, func(i, j int) bool {
 		return selectedWorlds[i].ID < selectedWorlds[j].ID

+ 1 - 1
frameworks/Go/go-std/src/storage/pgx.go

@@ -75,7 +75,7 @@ func (psql PGX) GetOneRandomWorld(w *World) error {
 }
 
 // UpdateWorlds updates some number of worlds entries, passed as arg
-func (psql PGX) UpdateWorlds(selectedWorlds []World, queries int) error {
+func (psql PGX) UpdateWorlds(selectedWorlds []World) error {
 	// against deadlocks
 	sort.Slice(selectedWorlds, func(i, j int) bool {
 		return selectedWorlds[i].ID < selectedWorlds[j].ID