X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/8da2f73faeeecd81f52949451fe07a674ba47df6..c89213f5a5e303050caaebe4f8fdf2980fc65605:/lib/costanalyzer/costanalyzer_test.go diff --git a/lib/costanalyzer/costanalyzer_test.go b/lib/costanalyzer/costanalyzer_test.go index b1ddf97a36..bf280ec0c5 100644 --- a/lib/costanalyzer/costanalyzer_test.go +++ b/lib/costanalyzer/costanalyzer_test.go @@ -53,7 +53,7 @@ func (s *Suite) SetUpSuite(c *check.C) { "IncludedScratch": 64000000000, "AddedScratch": 0, "Price": 0.292, - "Preemptible": false + "Preemptible": true }` standardD32sV3JSON := `{ "Name": "Standard_D32s_v3", @@ -158,6 +158,30 @@ func (*Suite) TestUsage(c *check.C) { c.Check(stderr.String(), check.Matches, `(?ms).*Usage:.*`) } +func (*Suite) TestTimestampRange(c *check.C) { + var stdout, stderr bytes.Buffer + resultsDir := c.MkDir() + // Run costanalyzer with a timestamp range. This should pick up two container requests in "Final" state. + exitcode := Command.RunCommand("costanalyzer.test", []string{"-output", resultsDir, "-begin", "2020-11-02T00:00:00", "-end", "2020-11-03T23:59:00"}, &bytes.Buffer{}, &stdout, &stderr) + c.Check(exitcode, check.Equals, 0) + c.Assert(stderr.String(), check.Matches, "(?ms).*supplied uuids in .*") + + uuidReport, err := ioutil.ReadFile(resultsDir + "/" + arvadostest.CompletedDiagnosticsContainerRequest1UUID + ".csv") + c.Assert(err, check.IsNil) + uuid2Report, err := ioutil.ReadFile(resultsDir + "/" + arvadostest.CompletedDiagnosticsContainerRequest2UUID + ".csv") + c.Assert(err, check.IsNil) + + c.Check(string(uuidReport), check.Matches, "(?ms).*TOTAL,,,,,,,,,0.00916192") + c.Check(string(uuid2Report), check.Matches, "(?ms).*TOTAL,,,,,,,,,0.00588088") + re := regexp.MustCompile(`(?ms).*supplied uuids in (.*?)\n`) + matches := re.FindStringSubmatch(stderr.String()) // matches[1] contains a string like 'results/2020-11-02-18-57-45-aggregate-costaccounting.csv' + + aggregateCostReport, err := ioutil.ReadFile(matches[1]) + c.Assert(err, check.IsNil) + + c.Check(string(aggregateCostReport), check.Matches, "(?ms).*TOTAL,0.01492030") +} + func (*Suite) TestContainerRequestUUID(c *check.C) { var stdout, stderr bytes.Buffer resultsDir := c.MkDir() @@ -168,6 +192,8 @@ func (*Suite) TestContainerRequestUUID(c *check.C) { uuidReport, err := ioutil.ReadFile(resultsDir + "/" + arvadostest.CompletedContainerRequestUUID + ".csv") c.Assert(err, check.IsNil) + // Make sure the 'preemptible' flag was picked up + c.Check(string(uuidReport), check.Matches, "(?ms).*,Standard_E4s_v3,true,.*") c.Check(string(uuidReport), check.Matches, "(?ms).*TOTAL,,,,,,,,,7.01302889") re := regexp.MustCompile(`(?ms).*supplied uuids in (.*?)\n`) matches := re.FindStringSubmatch(stderr.String()) // matches[1] contains a string like 'results/2020-11-02-18-57-45-aggregate-costaccounting.csv' @@ -288,6 +314,18 @@ func (*Suite) TestDoubleContainerRequestUUID(c *check.C) { c.Check(string(aggregateCostReport), check.Matches, "(?ms).*TOTAL,49.28334000") } +func (*Suite) TestUncommittedContainerRequest(c *check.C) { + var stdout, stderr bytes.Buffer + // Run costanalyzer with 2 container request uuids, one of which is in the Uncommitted state, without output directory specified + exitcode := Command.RunCommand("costanalyzer.test", []string{arvadostest.UncommittedContainerRequestUUID, arvadostest.CompletedDiagnosticsContainerRequest2UUID}, &bytes.Buffer{}, &stdout, &stderr) + c.Check(exitcode, check.Equals, 0) + c.Assert(stderr.String(), check.Not(check.Matches), "(?ms).*supplied uuids in .*") + c.Assert(stderr.String(), check.Matches, "(?ms).*No container associated with container request .*") + + // Check that the total amount was printed to stdout + c.Check(stdout.String(), check.Matches, "0.00588088\n") +} + func (*Suite) TestMultipleContainerRequestUUIDWithReuse(c *check.C) { var stdout, stderr bytes.Buffer // Run costanalyzer with 2 container request uuids, without output directory specified