Last active
August 8, 2019 17:36
-
-
Save rkuzner/139c792dd2e069f164e7bf5926f8cb44 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" | |
) | |
// valores que usaremos en todos los tests | |
const ( | |
Limite = 1000000 // valor maximo que queremos alcanzar con el contador | |
CargaDeTrabajo = 1 * time.Nanosecond // representa una carga de trabajo adicional previo a incrementar el contador | |
) | |
// TestContadorSecuencial incrementa un contador dentro de un loop | |
func TestContadorSecuencial(t *testing.T) { | |
var contador int64 | |
for i := 0; i < Limite; i++ { | |
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