chore: initialize containerized Go learning workbook (2026 DevOps/SRE)

This commit is contained in:
soda64 committed 2026-11-30 23:03:31 +01:00
commit 84be3e5d77
64 files changed
+1382

No files matched your search

@@ -0,0 +1,10 @@
# 07 — Współbieżność (`goroutines`, `channels`, `sync.WaitGroup`, `context`)
## Zadania (`concurrency.go`)
1. `ParallelSum(chunks [][]int) int` — policz sumę każdego kawałka równolegle w goroutines (użyj kanału lub `sync.WaitGroup` + `sync/atomic` / mutex) i zwróć łączną sumę.
2. `WaitOrCancel(ctx context.Context, ch <-chan string) (string, error)` — użyj `select` na `ch` i `ctx.Done()`.
## Uruchomienie testów (z `-race`!)
```bash
make test PKG=./exercises/01-core/07-concurrency
```
@@ -0,0 +1,11 @@
package concurrency
import "context"
func ParallelSum(chunks [][]int) int {
panic("TODO: policz sumę każdego chunka w osobnej goroutine i zsumuj wyniki bezpiecznie")
}
func WaitOrCancel(ctx context.Context, ch <-chan string) (string, error) {
panic("TODO: użyj select na <-ch oraz <-ctx.Done()")
}
@@ -0,0 +1,30 @@
package concurrency
import (
"context"
"testing"
"time"
)
func TestParallelSum(t *testing.T) {
chunks := [][]int{{1, 2, 3}, {4, 5}, {10, 20, 30}}
if got := ParallelSum(chunks); got != 75 {
t.Fatalf("got %d, want 75", got)
}
}
func TestWaitOrCancel(t *testing.T) {
ch := make(chan string, 1)
ch <- "ready"
got, err := WaitOrCancel(context.Background(), ch)
if err != nil || got != "ready" {
t.Fatalf("got (%q, %v), want (ready, nil)", got, err)
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
defer cancel()
never := make(chan string)
if _, err := WaitOrCancel(ctx, never); err == nil {
t.Fatal("expected context deadline error")
}
}