Skip to content

Commit

Permalink
[AUTOPR] Fix flaky test (Vonage#265)
Browse files Browse the repository at this point in the history
* Bump version

* Avoid duplicate inserts

* Fix flacky test

---------

Co-authored-by: nicolaasuni-vonage <[email protected]>
  • Loading branch information
github-actions[bot] and nicolaasuni-vonage authored Jul 27, 2024
1 parent 072b6a3 commit 3277531
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.99.0
1.99.1
2 changes: 1 addition & 1 deletion examples/service/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.22.5
replace github.com/Vonage/gosrvlib => ../..

require (
github.com/Vonage/gosrvlib v1.99.0
github.com/Vonage/gosrvlib v1.99.1
github.com/golang/mock v1.6.0
github.com/jstemmer/go-junit-report/v2 v2.1.0
github.com/prometheus/client_golang v1.19.1
Expand Down
44 changes: 24 additions & 20 deletions pkg/countryphone/countryphone.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,9 @@ func (d *Data) insertPrefix(prefix string, info *NumInfo) {
d.trie.Add(prefix, info)
}

func (d *Data) insertGroups(a2, cc string, data []InPrefixGroup) {
if len(data) == 0 {
return
}

for _, g := range data {
info := &NumInfo{
func (d *Data) insertGroups(a2 string, cdata *InCountryData) {
for _, g := range cdata.Groups {
groupInfo := &NumInfo{
Type: g.PrefixType,
Geo: []*GeoInfo{
{
Expand All @@ -207,12 +203,12 @@ func (d *Data) insertGroups(a2, cc string, data []InPrefixGroup) {
}

if len(g.Prefixes) == 0 {
d.insertPrefix(cc, info)
d.insertPrefix(cdata.CC, groupInfo)
continue
}

for _, p := range g.Prefixes {
d.insertPrefix(p, info)
d.insertPrefix(p, groupInfo)
}
}
}
Expand All @@ -221,19 +217,27 @@ func (d *Data) insertGroups(a2, cc string, data []InPrefixGroup) {
func (d *Data) loadData(data InData) {
d.trie = numtrie.New[NumInfo]()

for k, v := range data {
info := &NumInfo{
Type: 0,
Geo: []*GeoInfo{
{
Alpha2: k,
Area: "",
Type: 0,
doneRootCC := make(map[string]bool, (26*26)+1) // all possible CCs + 1 for non-geographic

for a2, cdata := range data {
if _, ok := doneRootCC[a2]; !ok {
// insert the root node for the country code only once
d.insertPrefix(cdata.CC, &NumInfo{
Type: 0,
Geo: []*GeoInfo{
{
Alpha2: a2,
Area: "",
Type: 0,
},
},
},
})

doneRootCC[a2] = true
}

d.insertPrefix(v.CC, info)
d.insertGroups(k, v.CC, v.Groups)
if len(cdata.Groups) > 0 {
d.insertGroups(a2, cdata)
}
}
}
6 changes: 4 additions & 2 deletions pkg/countryphone/countryphone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ func TestData_NumberInfo(t *testing.T) {
}

require.NoError(t, err)
require.EqualExportedValues(t, tt.want, got)
require.Equal(t, tt.want.Type, got.Type)
require.ElementsMatch(t, tt.want.Geo, got.Geo)
})
}
}
Expand Down Expand Up @@ -330,7 +331,8 @@ func TestData_NumberInfo_custom(t *testing.T) {
}

require.NoError(t, err)
require.EqualExportedValues(t, tt.want, got)
require.Equal(t, tt.want.Type, got.Type)
require.ElementsMatch(t, tt.want.Geo, got.Geo)
})
}
}
Expand Down

0 comments on commit 3277531

Please sign in to comment.