Created
August 8, 2019 17:37
-
-
Save rkuzner/2d489c5a99aba28ededc50ec74da8de8 to your computer and use it in GitHub Desktop.
Workshop Resiliencia - Demo Concurrencia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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