A practical Go repository built while learning and revising core backend development concepts related to concurrency, synchronization, testing, and performance benchmarking.
The goal of this repository is to understand how Go handles concurrent execution and how these concepts can be tested and measured using Go's built-in tooling.
Examples covering:
- Creating goroutines
- Passing parameters to goroutines
- Returning values using channels
- Running tasks concurrently
- Using
sync.WaitGroup - Concurrent user/data fetching examples
Examples covering:
- Creating channels
- Sending and receiving values
- Unbuffered channels
- Buffered channels
- Closing channels
- Channel communication
- Using channels to return values
- Using channels for synchronization
selectstatementselectwith timeout
Examples covering:
- Race conditions
sync.Mutexsync.RWMutex- Atomic operations
- Protecting shared data
- Synchronizing concurrent operations
Examples using Go's built-in testing package.
Covered concepts:
- Unit testing
go test- Verbose testing with
go test -v - Expected vs actual results
- Table-driven tests
- Subtests using
t.Run() - Race detection with
go test -race
Example:
go test ./...Verbose output:
go test -v ./...Race detection:
go test -race ./...Examples demonstrating Go's built-in benchmarking tools.
Covered concepts:
- Creating benchmark functions
testing.Bb.N- Comparing implementations
- Reading benchmark results
- Measuring memory allocations
Run benchmarks:
go test -bench=. ./...Run benchmarks with memory statistics:
go test -bench=. -benchmem ./...Benchmark output can include:
ns/op— nanoseconds per operationB/op— bytes allocated per operationallocs/op— allocations per operation
This repository contains a simple comparison between two ways of iterating through and summing a slice:
func Sum(numbers []int) int {
total := 0
for _, number := range numbers {
total += number
}
return total
}and an index-based implementation.
The implementations are compared using Go benchmarks.
Clone the repository:
git clone https://github.com/muhammadasad70/go-concurrency-testing-lab.gitMove into the project:
cd go-concurrency-testing-labDownload or verify module dependencies:
go mod tidyRun all tests:
go test ./...Run benchmarks:
go test -bench=. ./...- Go
- Goroutines
- Channels
- Mutex
- RWMutex
- Atomic Operations
- Go Testing
- Race Detector
- Go Benchmarking
This repository is part of my backend engineering learning journey, with a focus on understanding Go concepts through implementation rather than theory alone.
It will continue to evolve as I learn and implement more concurrency, testing, and performance concepts.