Skip to content

Commit

Permalink
chore: Enabling shuffling, cleanup and consistency across tests (#2931)
Browse files Browse the repository at this point in the history
* Make Test/Benchmark names consistent. Add Makefile for GoFiber developers

* Cleanup README and Makefile

* Update statement
  • Loading branch information
gaby authored Mar 24, 2024
1 parent 3209052 commit 95c1814
Show file tree
Hide file tree
Showing 17 changed files with 187 additions and 114 deletions.
48 changes: 39 additions & 9 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,20 @@
</a>
</p>
<p align="center">
<b>Fiber</b> is an <a href="https://github.com/expressjs/express">Express</a> inspired <b>web framework</b> built on top of <a href="https://github.com/valyala/fasthttp">Fasthttp</a>, the <b>fastest</b> HTTP engine for <a href="https://go.dev/doc/">Go</a>. Designed to <b>ease</b> things up for <b>fast</b> development with <b>zero memory allocation</b> and <b>performance</b> in mind.
<em><b>Fiber</b> is an <a href="https://github.com/expressjs/express">Express</a> inspired <b>web framework</b> built on top of <a href="https://github.com/valyala/fasthttp">Fasthttp</a>, the <b>fastest</b> HTTP engine for <a href="https://go.dev/doc/">Go</a>. Designed to <b>ease</b> things up for <b>fast</b> development with <b>zero memory allocation</b> and <b>performance</b> in mind.</em>
</p>

---

## ⚠️ **Attention**

Fiber v3 is currently in beta and under active development. While it offers exciting new features, please note that it may not be stable for production use. We recommend sticking to the latest stable release (v2.x) for mission-critical applications. If you choose to use v3, be prepared for potential bugs and breaking changes. Always check the official documentation and release notes for updates and proceed with caution. Happy coding! 🚀

## ⚙️ Installation
---

Before you begin, ensure you have Go installed on your system. Fiber requires **Go version `1.21` or higher** to run. You can check your current Go version by running `go version` in your terminal. If you need to install or upgrade Go, visit the [official Go download page](https://go.dev/dl/).
## ⚙️ Installation

Once you have verified your Go installation, you can start setting up your project. Create a new directory for your project and navigate into it. Then, initialize your project with Go modules by executing the following command in your terminal:
Fiber requires **Go version `1.21` or higher** to run. If you need to install or upgrade Go, visit the [official Go download page](https://go.dev/dl/). To start setting up your project. Create a new directory for your project and navigate into it. Then, initialize your project with Go modules by executing the following command in your terminal:

```bash
go mod init github.com/your/repo
Expand All @@ -60,7 +62,11 @@ Getting started with Fiber is easy. Here's a basic example to create a simple we
```go
package main

import "github.com/gofiber/fiber/v3"
import (
"log"

"github.com/gofiber/fiber/v3"
)

func main() {
// Initialize a new Fiber app
Expand All @@ -73,7 +79,7 @@ func main() {
})

// Start the server on port 3000
app.Listen(":3000")
log.Fatal(app.Listen(":3000"))
}
```

Expand Down Expand Up @@ -186,7 +192,6 @@ func main() {
// ]
// }


log.Fatal(app.Listen(":3000"))
}

Expand Down Expand Up @@ -262,6 +267,8 @@ Checkout our [Template](https://github.com/gofiber/template) package that suppor
package main

import (
"log"

"github.com/gofiber/fiber/v3"
"github.com/gofiber/template/pug"
)
Expand Down Expand Up @@ -437,6 +444,8 @@ func main() {

```go
import (
"log"

"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/middleware/websocket"
)
Expand Down Expand Up @@ -471,6 +480,8 @@ func main() {

```go
import (
"log"

"github.com/gofiber/fiber/v3"
"github.com/valyala/fasthttp"
)
Expand Down Expand Up @@ -512,6 +523,8 @@ func main() {

```go
import (
"log"

"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/middleware/recover"
)
Expand All @@ -537,6 +550,8 @@ func main() {

```go
import (
"log"

"github.com/gofiber/fiber/v3"
)

Expand Down Expand Up @@ -611,6 +626,21 @@ If you want to say **Thank You** and/or support the active development of `Fiber
3. Write a review or tutorial on [Medium](https://medium.com/), [Dev.to](https://dev.to/) or personal blog.
4. Support the project by donating a [cup of coffee](https://buymeacoff.ee/fenny).

## 🖥️ Development

To ensure your contributions are ready for a Pull Request, please use the following `Makefile` commands. These tools help maintain code quality, consistency.

* **make help**: Display available commands.
* **make audit**: Conduct quality checks.
* **make benchmark**: Benchmark code performance.
* **make coverage**: Generate test coverage report.
* **make format**: Automatically format code.
* **make lint**: Run lint checks.
* **make test**: Execute all tests.
* **make tidy**: Tidy dependencies.

Run these commands to ensure your code adheres to project standards and best practices.

## ☕ Supporters

Fiber is an open source project that runs on donations to pay the bills e.g. our domain name, gitbook, netlify and serverless hosting. If you want to support Fiber, you can ☕ [**buy a coffee here**](https://buymeacoff.ee/fenny).
Expand All @@ -636,14 +666,14 @@ Fiber is an open source project that runs on donations to pay the bills e.g. our
| ![](https://avatars.githubusercontent.com/u/31022056?s=25) | [@marvinjwendt](https://github.com/marvinjwendt) | ☕ x 1 |
| ![](https://avatars.githubusercontent.com/u/31921460?s=25) | [@toishy](https://github.com/toishy) | ☕ x 1 |

## ‎‍💻 Code Contributors
## 💻 Code Contributors

<img src="https://opencollective.com/fiber/contributors.svg?width=890&button=false" alt="Code Contributors" style="max-width:100%;">

## ⭐️ Stargazers

<img src="https://starchart.cc/gofiber/fiber.svg" alt="Stargazers over time" style="max-width: 100%">

## ⚠️ License
## 🧾 License

Copyright (c) 2019-present [Fenny](https://github.com/fenny) and [Contributors](https://github.com/gofiber/fiber/graphs/contributors). `Fiber` is free and open-source software licensed under the [MIT License](https://github.com/gofiber/fiber/blob/master/LICENSE). Official logo was created by [Vic Shóstak](https://github.com/koddr) and distributed under [Creative Commons](https://creativecommons.org/licenses/by-sa/4.0/) license (CC BY-SA 4.0 International).
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
run: go install gotest.tools/[email protected]

- name: Test
run: gotestsum -f testname -- ./... -race -count=1 -coverprofile=coverage.txt -covermode=atomic
run: gotestsum -f testname -- ./... -race -count=1 -coverprofile=coverage.txt -covermode=atomic -shuffle=on

- name: Upload coverage reports to Codecov
if: ${{ matrix.platform == 'ubuntu-latest' && matrix.go-version == '1.22.x' }}
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*.test
*.tmp

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Output of the go coverage tool
**/*.out

# IDE files
.vscode
Expand Down
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## help: 💡 Display available commands
.PHONY: help
help:
@echo '⚡️ GoFiber/Fiber Development:'
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'

## audit: 🚀 Conduct quality checks
.PHONY: audit
audit:
go mod verify
go vet ./...
go run golang.org/x/vuln/cmd/govulncheck@latest ./...

## benchmark: 📈 Benchmark code performance
.PHONY: benchmark
benchmark:
go test ./... -benchmem -bench=. -run=^Benchmark_$

## coverage: ☂️ Generate coverage report
.PHONY: coverage
coverage:
go run gotest.tools/gotestsum@latest -f testname -- ./... -race -count=1 -coverprofile=/tmp/coverage.out -covermode=atomic
go tool cover -html=/tmp/coverage.out

## format: 🎨 Fix code format issues
.PHONY: format
format:
go run mvdan.cc/gofumpt@latest -w -l .

## lint: 🚨 Run lint checks
.PHONY: lint
lint:
go run github.com/golangci/golangci-lint/cmd/[email protected] run ./...

## test: 🚦 Execute all tests
.PHONY: test
test:
go run gotest.tools/gotestsum@latest -f testname -- ./... -race -count=1 -shuffle=on

## tidy: 📌 Clean and tidy dependencies
.PHONY: tidy
tidy:
go mod tidy -v
4 changes: 2 additions & 2 deletions addon/retry/exponential_backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/require"
)

func TestExponentialBackoff_Retry(t *testing.T) {
func Test_ExponentialBackoff_Retry(t *testing.T) {
t.Parallel()
tests := []struct {
name string
Expand Down Expand Up @@ -60,7 +60,7 @@ func TestExponentialBackoff_Retry(t *testing.T) {
}
}

func TestExponentialBackoff_Next(t *testing.T) {
func Test_ExponentialBackoff_Next(t *testing.T) {
t.Parallel()
tests := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1809,7 +1809,7 @@ func Test_App_AddCustomRequestMethod(t *testing.T) {
require.Equal(t, "TEST", appMethods[len(appMethods)-1])
}

func TestApp_GetRoutes(t *testing.T) {
func Test_App_GetRoutes(t *testing.T) {
t.Parallel()
app := New()
app.Use(func(c Ctx) error {
Expand Down
12 changes: 6 additions & 6 deletions client/cookiejar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func checkKeyValue(t *testing.T, cj *CookieJar, cookie *fasthttp.Cookie, uri *fa
require.Equal(t, string(c.Value()), string(cookie.Value()))
}

func TestCookieJarGet(t *testing.T) {
func Test_CookieJarGet(t *testing.T) {
t.Parallel()

url := []byte("http://fasthttp.com/")
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestCookieJarGet(t *testing.T) {
}
}

func TestCookieJarGetExpired(t *testing.T) {
func Test_CookieJarGetExpired(t *testing.T) {
t.Parallel()

url1 := []byte("http://fasthttp.com/make/")
Expand All @@ -116,7 +116,7 @@ func TestCookieJarGetExpired(t *testing.T) {
require.Empty(t, cookies)
}

func TestCookieJarSet(t *testing.T) {
func Test_CookieJarSet(t *testing.T) {
t.Parallel()

url := []byte("http://fasthttp.com/hello/world")
Expand All @@ -133,7 +133,7 @@ func TestCookieJarSet(t *testing.T) {
checkKeyValue(t, cj, cookie, uri, 1)
}

func TestCookieJarSetRepeatedCookieKeys(t *testing.T) {
func Test_CookieJarSetRepeatedCookieKeys(t *testing.T) {
t.Parallel()
host := "fast.http"
cj := &CookieJar{}
Expand Down Expand Up @@ -161,7 +161,7 @@ func TestCookieJarSetRepeatedCookieKeys(t *testing.T) {
require.True(t, bytes.Equal(cookies[0].Value(), cookie2.Value()))
}

func TestCookieJarSetKeyValue(t *testing.T) {
func Test_CookieJarSetKeyValue(t *testing.T) {
t.Parallel()

host := "fast.http"
Expand All @@ -179,7 +179,7 @@ func TestCookieJarSetKeyValue(t *testing.T) {
require.Len(t, cookies, 2)
}

func TestCookieJarGetFromResponse(t *testing.T) {
func Test_CookieJarGetFromResponse(t *testing.T) {
t.Parallel()

res := fasthttp.AcquireResponse()
Expand Down
Loading

1 comment on commit 95c1814

@ReneWerner87
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 95c1814 Previous: 1607d87 Ratio
Benchmark_Etag 201.3 ns/op 0 B/op 0 allocs/op 97.85 ns/op 0 B/op 0 allocs/op 2.06
Benchmark_Middleware_Favicon 209.3 ns/op 12 B/op 4 allocs/op 88.92 ns/op 3 B/op 1 allocs/op 2.35

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.