Giter Site home page Giter Site logo

go-tests's Introduction

Go tests

Examples to demonstrate use of go tests with/without parallel flags

  1. Sequential - 5 Tests each having 1S sleep without t.Parallel() statements.
  2. Parallel - 5 Tests each having 1S sleep with t.Parallel() statements.

Running tests without parallel flag (Default parallel flag value is GOMAXPROCS, equals runtime.NumCPU)

GOMAXPROCS - The GOMAXPROCS variable limits the number of operating system threads that can execute user-level Go code simultaneously

  1. Sequential tests
go test -v .\sequential_test.go

Results

=== RUN   TestSerial
=== RUN   TestSerial/First
***** Running First test =====
===== First test complete *****
=== RUN   TestSerial/Second
***** Running Second test =====
===== Second test complete *****
=== RUN   TestSerial/Third
***** Running Third test =====
===== Third test complete *****
=== RUN   TestSerial/Fourth
***** Running Fourth test =====
===== Fourth test complete *****
=== RUN   TestSerial/Fifth
***** Running Fifth test =====
===== Fifth test complete *****
--- PASS: TestSerial (5.03s)
    --- PASS: TestSerial/First (1.00s)
    --- PASS: TestSerial/Second (1.01s)
    --- PASS: TestSerial/Third (1.01s)
    --- PASS: TestSerial/Fourth (1.01s)
    --- PASS: TestSerial/Fifth (1.01s)
PASS
ok      command-line-arguments  7.226s
  1. Parallel tests
go test -v .\parallel_test.go

Results

=== RUN   TestParallel
=== RUN   TestParallel/First
=== PAUSE TestParallel/First
=== RUN   TestParallel/Second
=== PAUSE TestParallel/Second
=== RUN   TestParallel/Third
=== PAUSE TestParallel/Third
=== RUN   TestParallel/Fourth
=== PAUSE TestParallel/Fourth
=== RUN   TestParallel/Fifth
=== PAUSE TestParallel/Fifth
=== CONT  TestParallel/First
***** Running First test =====
=== CONT  TestParallel/Second
***** Running Second test =====
=== CONT  TestParallel/Fifth
***** Running Fifth test =====
=== CONT  TestParallel/Fourth
***** Running Fourth test =====
=== CONT  TestParallel/Third
***** Running Third test =====
===== Second test complete *****
===== Third test complete *****
===== Fourth test complete *****
===== First test complete *****
===== Fifth test complete *****
--- PASS: TestParallel (0.00s)
    --- PASS: TestParallel/Third (1.01s)
    --- PASS: TestParallel/Fourth (1.01s)
    --- PASS: TestParallel/Fifth (1.01s)
    --- PASS: TestParallel/First (1.01s)
    --- PASS: TestParallel/Second (1.01s)
PASS
ok      command-line-arguments  1.131s

Running tests with parallel flag = 1

  1. Sequential tests
go test -v .\sequential_test.go -parallel 1

Results

=== RUN   TestSerial
=== RUN   TestSerial/First
***** Running First test =====
===== First test complete *****
=== RUN   TestSerial/Second
***** Running Second test =====
===== Second test complete *****
=== RUN   TestSerial/Third
***** Running Third test =====
===== Third test complete *****
=== RUN   TestSerial/Fourth
***** Running Fourth test =====
===== Fourth test complete *****
=== RUN   TestSerial/Fifth
***** Running Fifth test =====
===== Fifth test complete *****
--- PASS: TestSerial (5.04s)
    --- PASS: TestSerial/First (1.00s)
    --- PASS: TestSerial/Second (1.01s)
    --- PASS: TestSerial/Third (1.01s)
    --- PASS: TestSerial/Fourth (1.01s)
    --- PASS: TestSerial/Fifth (1.01s)
PASS
ok      command-line-arguments  5.178s
  1. Parallel tests
go test -v .\parallel_test.go -parallel 1

Results

=== RUN   TestParallel
=== RUN   TestParallel/First
=== PAUSE TestParallel/First
=== RUN   TestParallel/Second
=== PAUSE TestParallel/Second
=== RUN   TestParallel/Third
=== PAUSE TestParallel/Third
=== RUN   TestParallel/Fourth
=== PAUSE TestParallel/Fourth
=== RUN   TestParallel/Fifth
=== PAUSE TestParallel/Fifth
=== CONT  TestParallel/First
***** Running First test =====
===== First test complete *****
=== CONT  TestParallel/Fourth
***** Running Fourth test =====
===== Fourth test complete *****
=== CONT  TestParallel/Fifth
***** Running Fifth test =====
===== Fifth test complete *****
=== CONT  TestParallel/Third
***** Running Third test =====
===== Third test complete *****
=== CONT  TestParallel/Second
***** Running Second test =====
===== Second test complete *****
--- PASS: TestParallel (0.00s)
    --- PASS: TestParallel/First (1.00s)
    --- PASS: TestParallel/Fourth (1.01s)
    --- PASS: TestParallel/Fifth (1.01s)
    --- PASS: TestParallel/Third (1.01s)
    --- PASS: TestParallel/Second (1.01s)
PASS
ok      command-line-arguments  5.160s

Running tests with parallel flag = 8

  1. Sequential tests
go test -v .\sequential_test.go -parallel 8

Results

=== RUN   TestSerial
=== RUN   TestSerial/First
***** Running First test =====
===== First test complete *****
=== RUN   TestSerial/Second
***** Running Second test =====
===== Second test complete *****
=== RUN   TestSerial/Third
***** Running Third test =====
===== Third test complete *****
=== RUN   TestSerial/Fourth
***** Running Fourth test =====
===== Fourth test complete *****
=== RUN   TestSerial/Fifth
***** Running Fifth test =====
===== Fifth test complete *****
--- PASS: TestSerial (5.04s)
    --- PASS: TestSerial/First (1.01s)
    --- PASS: TestSerial/Second (1.01s)
    --- PASS: TestSerial/Third (1.01s)
    --- PASS: TestSerial/Fourth (1.01s)
    --- PASS: TestSerial/Fifth (1.01s)
PASS
ok      command-line-arguments  5.165s
  1. Parallel tests
go test -v .\parallel_test.go -parallel 8

Results

=== RUN   TestParallel
=== RUN   TestParallel/First
=== PAUSE TestParallel/First
=== RUN   TestParallel/Second
=== PAUSE TestParallel/Second
=== RUN   TestParallel/Third
=== PAUSE TestParallel/Third
=== RUN   TestParallel/Fourth
=== PAUSE TestParallel/Fourth
=== RUN   TestParallel/Fifth
=== PAUSE TestParallel/Fifth
=== CONT  TestParallel/First
***** Running First test =====
=== CONT  TestParallel/Fifth
***** Running Fifth test =====
=== CONT  TestParallel/Fourth
***** Running Fourth test =====
=== CONT  TestParallel/Third
***** Running Third test =====
=== CONT  TestParallel/Second
***** Running Second test =====
===== Fifth test complete *****
===== Second test complete *****
===== First test complete *****
===== Third test complete *****
===== Fourth test complete *****
--- PASS: TestParallel (0.00s)
    --- PASS: TestParallel/Fifth (1.01s)
    --- PASS: TestParallel/First (1.01s)
    --- PASS: TestParallel/Second (1.01s)
    --- PASS: TestParallel/Fourth (1.01s)
    --- PASS: TestParallel/Third (1.01s)
PASS
ok      command-line-arguments  1.135s

go-tests's People

Contributors

sacoo7 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.