Пример #1
0
func (s *StatsTestSuite) TestRoundRobinFull(t *C) {
	ss := data.NewSenderStats(time.Duration(3 * time.Second))
	t.Assert(ss, NotNil)

	d := ss.Dump()
	t.Check(d, HasLen, 0)

	for _, info := range s.send {
		ss.Sent(info)
	}

	d = ss.Dump()
	if len(d) != 4 {
		Dump(d)
		t.Errorf("len(d)=%d, expected 4", len(d))
	}
	if same, diff := IsDeeply(d[0], s.send[2]); !same {
		t.Error(diff)
	}
	if same, diff := IsDeeply(d[1], s.send[3]); !same {
		t.Error(diff)
	}
	if same, diff := IsDeeply(d[2], s.send[4]); !same {
		t.Error(diff)
	}
	if same, diff := IsDeeply(d[3], s.send[5]); !same {
		t.Error(diff)
	}

	got := ss.Report()
	expect := data.SentReport{
		Begin:       s.send[2].Begin,
		End:         s.send[5].End,
		Bytes:       "5.84 MB",
		Duration:    "3.8s",
		Utilization: "12.29 Mbps",
		Throughput:  "20.76 Mbps",
		Files:       7,
		Errs:        0,
		ApiErrs:     0,
		Timeouts:    0,
		BadFiles:    0,
	}
	if same, diff := IsDeeply(got, expect); !same {
		Dump(got)
		t.Error(diff)
	}

	t.Check(
		data.FormatSentReport(got),
		Equals,
		fmt.Sprintf(data.BaseReportFormat,
			expect.Files, expect.Bytes, expect.Duration, expect.Utilization, expect.Throughput),
	)
}
Пример #2
0
func (s *StatsTestSuite) TestErrors(t *C) {
	ss := data.NewSenderStats(time.Duration(10 * time.Second))
	t.Assert(ss, NotNil)

	d := ss.Dump()
	t.Check(d, HasLen, 0)

	// Copy data so we can add errors.
	send := make([]data.SentInfo, len(s.send))
	for i, info := range s.send {
		send[i] = info
	}
	send[0].Errs++
	send[1].ApiErrs++
	send[2].BadFiles++
	send[3].Timeouts++
	for _, info := range send {
		ss.Sent(info)
	}

	d = ss.Dump()
	if len(d) != len(send) {
		Dump(d)
		t.Errorf("len(d)=%d, expected %d", len(d), len(send))
	}

	got := ss.Report()
	expect := data.SentReport{
		Begin:       send[0].Begin,
		End:         send[5].End,
		Bytes:       "5.87 MB",
		Duration:    "5.8s",
		Utilization: "8.10 Mbps",
		Throughput:  "17.08 Mbps",
		Files:       9,
		Errs:        1,
		ApiErrs:     1,
		Timeouts:    1,
		BadFiles:    1,
	}
	if same, diff := IsDeeply(got, expect); !same {
		Dump(got)
		t.Error(diff)
	}

	t.Check(
		data.FormatSentReport(got),
		Equals,
		fmt.Sprintf(data.BaseReportFormat+", "+data.ErrorReportFormat,
			expect.Files, expect.Bytes, expect.Duration, expect.Utilization, expect.Throughput,
			expect.Errs, expect.ApiErrs, expect.Timeouts, expect.BadFiles),
	)
}