Skip to content

Instantly share code, notes, and snippets.

@rkuzner
Created August 8, 2019 17:37
Show Gist options
  • Save rkuzner/2d489c5a99aba28ededc50ec74da8de8 to your computer and use it in GitHub Desktop.
Save rkuzner/2d489c5a99aba28ededc50ec74da8de8 to your computer and use it in GitHub Desktop.
Workshop Resiliencia - Demo Concurrencia
package contador_test
import (
"fmt"
"testing"
"time"
)
// TestContadorConcurrente incrementa un contador con goroutines
func TestContadorConcurrente(t *testing.T) {
var contador int64
for i := 0; i < Limite; i++ {
go func() {
time.Sleep(CargaDeTrabajo)
contador++
}()
}
if contador != Limite {
t.Errorf("el contador NO alcanzó el límite: %d", contador)
} else {
fmt.Println(fmt.Sprintf("%s: el contador alcanzo el límite!", t.Name()))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment