@@ -1613,9 +1613,210 @@ func TestBenchSpy_CompareDirectWithThresholds(t *testing.T) {
16131613 assert .Len (t , errs , 1 )
16141614 assert .Len (t , errs ["test-gen" ], 4 )
16151615 for _ , err := range errs ["test-gen" ] {
1616- assert .Contains (t , err .Error (), "100 .0000% different" )
1616+ assert .Contains (t , err .Error (), "999 .0000% different" )
16171617 }
16181618 })
1619+
1620+ t .Run ("handle non-zero to zero transition" , func (t * testing.T ) {
1621+ previousReport := & StandardReport {
1622+ BasicData : BasicData {
1623+ GeneratorConfigs : map [string ]* wasp.Config {
1624+ "test-gen" : {
1625+ GenName : "test-gen" ,
1626+ },
1627+ },
1628+ },
1629+ QueryExecutors : []QueryExecutor {
1630+ & MockQueryExecutor {
1631+ KindFn : func () string { return string (StandardQueryExecutor_Direct ) },
1632+ ResultsFn : func () map [string ]interface {} {
1633+ return map [string ]interface {}{
1634+ string (MedianLatency ): 10.0 ,
1635+ string (Percentile95Latency ): 20.0 ,
1636+ string (MaxLatency ): 311.0 ,
1637+ string (ErrorRate ): 1.0 ,
1638+ }
1639+ },
1640+ GeneratorNameFn : func () string { return "test-gen" },
1641+ },
1642+ },
1643+ }
1644+
1645+ currentReport := & StandardReport {
1646+ BasicData : BasicData {
1647+ GeneratorConfigs : map [string ]* wasp.Config {
1648+ "test-gen" : {
1649+ GenName : "test-gen" ,
1650+ },
1651+ },
1652+ },
1653+ QueryExecutors : []QueryExecutor {
1654+ & MockQueryExecutor {
1655+ KindFn : func () string { return string (StandardQueryExecutor_Direct ) },
1656+ ResultsFn : func () map [string ]interface {} {
1657+ return map [string ]interface {}{
1658+ string (MedianLatency ): 0.0 ,
1659+ string (Percentile95Latency ): 0.0 ,
1660+ string (MaxLatency ): 0.0 ,
1661+ string (ErrorRate ): 0.0 ,
1662+ }
1663+ },
1664+ GeneratorNameFn : func () string { return "test-gen" },
1665+ },
1666+ },
1667+ }
1668+
1669+ failed , errs := CompareDirectWithThresholds (10.0 , 10.0 , 10.0 , 10.0 , currentReport , previousReport )
1670+ assert .False (t , failed )
1671+ assert .Len (t , errs , 0 )
1672+ })
1673+
1674+ t .Run ("handle edge-cases" , func (t * testing.T ) {
1675+ previousReport := & StandardReport {
1676+ BasicData : BasicData {
1677+ GeneratorConfigs : map [string ]* wasp.Config {
1678+ "test-gen" : {
1679+ GenName : "test-gen" ,
1680+ },
1681+ },
1682+ },
1683+ QueryExecutors : []QueryExecutor {
1684+ & MockQueryExecutor {
1685+ KindFn : func () string { return string (StandardQueryExecutor_Direct ) },
1686+ ResultsFn : func () map [string ]interface {} {
1687+ return map [string ]interface {}{
1688+ string (MedianLatency ): 10.1 ,
1689+ string (Percentile95Latency ): 10.1 ,
1690+ string (MaxLatency ): 10.0 ,
1691+ string (ErrorRate ): 10.0 ,
1692+ }
1693+ },
1694+ GeneratorNameFn : func () string { return "test-gen" },
1695+ },
1696+ },
1697+ }
1698+
1699+ currentReport := & StandardReport {
1700+ BasicData : BasicData {
1701+ GeneratorConfigs : map [string ]* wasp.Config {
1702+ "test-gen" : {
1703+ GenName : "test-gen" ,
1704+ },
1705+ },
1706+ },
1707+ QueryExecutors : []QueryExecutor {
1708+ & MockQueryExecutor {
1709+ KindFn : func () string { return string (StandardQueryExecutor_Direct ) },
1710+ ResultsFn : func () map [string ]interface {} {
1711+ return map [string ]interface {}{
1712+ string (MedianLatency ): 10.2 ,
1713+ string (Percentile95Latency ): 10.1999 ,
1714+ string (MaxLatency ): 0.0 ,
1715+ string (ErrorRate ): 0.0 ,
1716+ }
1717+ },
1718+ GeneratorNameFn : func () string { return "test-gen" },
1719+ },
1720+ },
1721+ }
1722+
1723+ failed , errs := CompareDirectWithThresholds (0.99 , 0.9892 , 10.0 , 10.0 , currentReport , previousReport )
1724+ assert .True (t , failed )
1725+ assert .Equal (t , 1 , len (errs ))
1726+ assert .Equal (t , 1 , len (errs ["test-gen" ]))
1727+ assert .Contains (t , errs ["test-gen" ][0 ].Error (), "0.9901% different" )
1728+ })
1729+
1730+ t .Run ("handle nil reports" , func (t * testing.T ) {
1731+ report := & StandardReport {
1732+ BasicData : BasicData {
1733+ GeneratorConfigs : map [string ]* wasp.Config {
1734+ "test-gen" : {
1735+ GenName : "test-gen" ,
1736+ },
1737+ },
1738+ },
1739+ QueryExecutors : []QueryExecutor {
1740+ & MockQueryExecutor {
1741+ KindFn : func () string { return string (StandardQueryExecutor_Direct ) },
1742+ ResultsFn : func () map [string ]interface {} {
1743+ return map [string ]interface {}{
1744+ string (MedianLatency ): 10.2 ,
1745+ string (Percentile95Latency ): 10.1999 ,
1746+ string (MaxLatency ): 0.0 ,
1747+ string (ErrorRate ): 0.0 ,
1748+ }
1749+ },
1750+ GeneratorNameFn : func () string { return "test-gen" },
1751+ },
1752+ },
1753+ }
1754+
1755+ failed , errs := CompareDirectWithThresholds (10.0 , 10.0 , 10.0 , 10.0 , report , nil )
1756+ assert .True (t , failed )
1757+ assert .Equal (t , 1 , len (errs ))
1758+ assert .Equal (t , 1 , len (errs ["initialization" ]))
1759+ assert .Contains (t , errs ["initialization" ][0 ].Error (), "one or both reports are nil" )
1760+
1761+ failed , errs = CompareDirectWithThresholds (10.0 , 10.0 , 10.0 , 10.0 , nil , report )
1762+ assert .True (t , failed )
1763+ assert .Equal (t , 1 , len (errs ))
1764+ assert .Equal (t , 1 , len (errs ["initialization" ]))
1765+ assert .Contains (t , errs ["initialization" ][0 ].Error (), "one or both reports are nil" )
1766+
1767+ failed , errs = CompareDirectWithThresholds (10.0 , 10.0 , 10.0 , 10.0 , nil , nil )
1768+ assert .True (t , failed )
1769+ assert .Equal (t , 1 , len (errs ))
1770+ assert .Equal (t , 1 , len (errs ["initialization" ]))
1771+ assert .Contains (t , errs ["initialization" ][0 ].Error (), "one or both reports are nil" )
1772+ })
1773+
1774+ t .Run ("handle incorrect thresholds" , func (t * testing.T ) {
1775+ report := & StandardReport {
1776+ BasicData : BasicData {
1777+ GeneratorConfigs : map [string ]* wasp.Config {
1778+ "test-gen" : {
1779+ GenName : "test-gen" ,
1780+ },
1781+ },
1782+ },
1783+ QueryExecutors : []QueryExecutor {
1784+ & MockQueryExecutor {
1785+ KindFn : func () string { return string (StandardQueryExecutor_Direct ) },
1786+ ResultsFn : func () map [string ]interface {} {
1787+ return map [string ]interface {}{
1788+ string (MedianLatency ): 10.0 ,
1789+ string (Percentile95Latency ): 10.0 ,
1790+ string (MaxLatency ): 0.0 ,
1791+ string (ErrorRate ): 0.0 ,
1792+ }
1793+ },
1794+ GeneratorNameFn : func () string { return "test-gen" },
1795+ },
1796+ },
1797+ }
1798+
1799+ failed , errs := CompareDirectWithThresholds (- 0.1 , 100.0 , 0.0 , 100.0 , report , report )
1800+ assert .True (t , failed )
1801+ assert .Equal (t , 1 , len (errs ))
1802+ assert .Equal (t , 1 , len (errs ["initialization" ]))
1803+ assert .Contains (t , errs ["initialization" ][0 ].Error (), "median threshold -0.1000 is not in the range [0, 100]" )
1804+
1805+ failed , errs = CompareDirectWithThresholds (1.0 , 101.0 , 0.0 , 100.0 , report , report )
1806+ assert .True (t , failed )
1807+ assert .Equal (t , 1 , len (errs ))
1808+ assert .Equal (t , 1 , len (errs ["initialization" ]))
1809+ assert .Contains (t , errs ["initialization" ][0 ].Error (), "p95 threshold 101.0000 is not in the range [0, 100]" )
1810+
1811+ failed , errs = CompareDirectWithThresholds (- 1 , - 1 , - 1 , - 1 , report , report )
1812+ assert .True (t , failed )
1813+ assert .Equal (t , 1 , len (errs ))
1814+ assert .Equal (t , 4 , len (errs ["initialization" ]))
1815+ assert .Contains (t , errs ["initialization" ][0 ].Error (), "median threshold -1.0000 is not in the range [0, 100]" )
1816+ assert .Contains (t , errs ["initialization" ][1 ].Error (), "p95 threshold -1.0000 is not in the range [0, 100]" )
1817+ assert .Contains (t , errs ["initialization" ][2 ].Error (), "max threshold -1.0000 is not in the range [0, 100]" )
1818+ assert .Contains (t , errs ["initialization" ][3 ].Error (), "error rate threshold -1.0000 is not in the range [0, 100]" )
1819+ })
16191820}
16201821
16211822func TestBenchSpy_Standard_Direct_Metrics_Two_Generators_E2E (t * testing.T ) {
0 commit comments