@@ -17,6 +17,7 @@ package internal
17
17
import (
18
18
"context"
19
19
"net/url"
20
+ "sync"
20
21
"testing"
21
22
"time"
22
23
@@ -1492,7 +1493,7 @@ func TestGenerateClientID(t *testing.T) {
1492
1493
}
1493
1494
1494
1495
// validate no data race is happening when updating rule properties in manifest while matching.
1495
- func TestRaceUpdatingRulesWhileMatching (t * testing.T ) {
1496
+ func TestUpdatingRulesWhileMatchingConcurrentSafe (t * testing.T ) {
1496
1497
// getSamplingRules response
1497
1498
ruleRecords := samplingRuleRecords {
1498
1499
SamplingRule : & ruleProperties {
@@ -1546,7 +1547,9 @@ func TestRaceUpdatingRulesWhileMatching(t *testing.T) {
1546
1547
}
1547
1548
1548
1549
// async rule updates
1550
+ done := make (chan struct {})
1549
1551
go func () {
1552
+ defer close (done )
1550
1553
for i := 0 ; i < 100 ; i ++ {
1551
1554
m .updateRules (s )
1552
1555
time .Sleep (time .Millisecond )
@@ -1559,10 +1562,11 @@ func TestRaceUpdatingRulesWhileMatching(t *testing.T) {
1559
1562
require .NoError (t , err )
1560
1563
require .False (t , match )
1561
1564
}
1565
+ <- done
1562
1566
}
1563
1567
1564
1568
// validate no data race is happening when updating rule properties and rule targets in manifest while matching.
1565
- func TestRaceUpdatingRulesAndTargetsWhileMatching (t * testing.T ) {
1569
+ func TestUpdatingRulesAndTargetsWhileMatchingConcurrentSafe (t * testing.T ) {
1566
1570
// getSamplingRules response to update existing manifest rule
1567
1571
ruleRecords := samplingRuleRecords {
1568
1572
SamplingRule : & ruleProperties {
@@ -1610,8 +1614,12 @@ func TestRaceUpdatingRulesAndTargetsWhileMatching(t *testing.T) {
1610
1614
clock : clock ,
1611
1615
}
1612
1616
1617
+ var wg sync.WaitGroup
1618
+
1613
1619
// async rule updates
1620
+ wg .Add (1 )
1614
1621
go func () {
1622
+ defer wg .Done ()
1615
1623
for i := 0 ; i < 100 ; i ++ {
1616
1624
m .updateRules (& getSamplingRulesOutput {
1617
1625
SamplingRuleRecords : []* samplingRuleRecords {& ruleRecords },
@@ -1621,7 +1629,9 @@ func TestRaceUpdatingRulesAndTargetsWhileMatching(t *testing.T) {
1621
1629
}()
1622
1630
1623
1631
// async target updates
1632
+ wg .Add (1 )
1624
1633
go func () {
1634
+ defer wg .Done ()
1625
1635
for i := 0 ; i < 100 ; i ++ {
1626
1636
manifest := m .deepCopy ()
1627
1637
@@ -1642,6 +1652,8 @@ func TestRaceUpdatingRulesAndTargetsWhileMatching(t *testing.T) {
1642
1652
require .False (t , match )
1643
1653
time .Sleep (time .Millisecond )
1644
1654
}
1655
+
1656
+ wg .Wait ()
1645
1657
}
1646
1658
1647
1659
// Validate Rules are preserved when a rule is updated with the same ruleProperties.
@@ -1782,7 +1794,7 @@ func TestDoNotPreserveRulesWithDifferentRuleProperties(t *testing.T) {
1782
1794
}
1783
1795
1784
1796
// validate no data race is when capturing sampling statistics in manifest while sampling.
1785
- func TestRaceUpdatingSamplingStatisticsWhenSampling (t * testing.T ) {
1797
+ func TestUpdatingSamplingStatisticsWhenSamplingConcurrentSafe (t * testing.T ) {
1786
1798
// existing rule already present in manifest
1787
1799
r1 := Rule {
1788
1800
ruleProperties : ruleProperties {
@@ -1819,7 +1831,9 @@ func TestRaceUpdatingSamplingStatisticsWhenSampling(t *testing.T) {
1819
1831
}
1820
1832
1821
1833
// async snapshot updates
1834
+ done := make (chan struct {})
1822
1835
go func () {
1836
+ defer close (done )
1823
1837
for i := 0 ; i < 100 ; i ++ {
1824
1838
manifest := m .deepCopy ()
1825
1839
@@ -1838,4 +1852,5 @@ func TestRaceUpdatingSamplingStatisticsWhenSampling(t *testing.T) {
1838
1852
_ = r1 .Sample (sdktrace.SamplingParameters {}, time .Unix (clock .nowTime + int64 (i ), 0 ))
1839
1853
time .Sleep (time .Millisecond )
1840
1854
}
1855
+ <- done
1841
1856
}
0 commit comments