aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


tools/stress/measurements_test.go (2364B)


      1 package main
      2 
      3 import (
      4 	"bytes"
      5 	"encoding/json"
      6 	"testing"
      7 	"time"
      8 )
      9 
     10 func TestCollectKeepsHotAndQuietZoneMeasurementsSeparate(t *testing.T) {
     11 	started := time.Now()
     12 	events := make(chan event, 10)
     13 	for _, result := range []event{
     14 		{playfield: 705, kind: "attempted"},
     15 		{playfield: 800, kind: "attempted"},
     16 		{playfield: 705, kind: "ready", elapsed: 500 * time.Millisecond},
     17 		{playfield: 800, kind: "ready", elapsed: time.Millisecond},
     18 		{playfield: 705, kind: "action", at: started, elapsed: 30 * time.Millisecond},
     19 		{playfield: 705, kind: "action", at: started.Add(time.Second), elapsed: 900 * time.Millisecond},
     20 		{playfield: 800, kind: "action", at: started.Add(time.Second), elapsed: 2 * time.Millisecond},
     21 		{playfield: 705, kind: "late", missed: 7},
     22 		{playfield: 705, kind: "traffic", packets: 12, bytes: 1234},
     23 		{playfield: 800, kind: "unanswered_action"},
     24 	} {
     25 		events <- result
     26 	}
     27 	close(events)
     28 	var output bytes.Buffer
     29 
     30 	if err := collect(&output, events, started, time.Second); err != nil {
     31 		t.Fatal(err)
     32 	}
     33 
     34 	type measurement struct {
     35 		Counts    map[string]int
     36 		Admission map[string]int
     37 		Steady    map[string]int `json:"steady_action"`
     38 	}
     39 	var report struct {
     40 		Phase  string
     41 		Counts map[string]int
     42 		Zones  map[uint32]measurement
     43 	}
     44 	if err := json.Unmarshal(output.Bytes(), &report); err != nil {
     45 		t.Fatal(err)
     46 	}
     47 	if report.Phase != "complete" || report.Counts["action"] != 3 || report.Counts["steady_actions"] != 2 || len(report.Zones) != 2 {
     48 		t.Fatal("incorrect combined measurements", report)
     49 	}
     50 	if report.Zones[705].Admission["p99_ms"] != 500 || report.Zones[705].Steady["p50_ms"] != 900 ||
     51 		report.Zones[705].Counts["action"] != 2 || report.Zones[705].Counts["steady_actions"] != 1 ||
     52 		report.Zones[705].Counts["missed_actions"] != 7 || report.Zones[705].Counts["received_packets"] != 12 ||
     53 		report.Zones[705].Counts["received_bytes"] != 1234 {
     54 		t.Fatal("hot zone measurements mixed with another zone or the ramp", report.Zones[705])
     55 	}
     56 	if report.Zones[800].Admission["p99_ms"] != 1 || report.Zones[800].Steady["p99_ms"] != 2 ||
     57 		report.Zones[800].Counts["action"] != 1 || report.Zones[800].Counts["missed_actions"] != 0 ||
     58 		report.Zones[800].Counts["unanswered_action"] != 1 || report.Zones[800].Counts["received_bytes"] != 0 {
     59 		t.Fatal("quiet zone measurements contaminated by the hot zone", report.Zones[800])
     60 	}
     61 }