Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
ef8cee4
feat(metadata): add internal RWMutex for MetadataInfo and fix json se…
jieguo-coder Jun 3, 2026
605d0b2
feat(metadata): add lock protection for global registry and instances…
jieguo-coder Jun 3, 2026
abf50a7
feat(metadata): fix concurrency safety in listener callbacks and exte…
jieguo-coder Jun 3, 2026
8bc0aaa
style: format import blocks using dubbo-go imports-formatter
jieguo-coder Jun 3, 2026
ea83f92
style: format metadata.go and report_instance.go to pass CI
jieguo-coder Jun 3, 2026
0048c16
fix(metadata): resolve data races pointed out in code review
jieguo-coder Jun 4, 2026
e65f694
test: fix failing tests and improve unit test coverage
jieguo-coder Jun 4, 2026
a7bad03
test: fix testifylint error by avoiding require in goroutines
jieguo-coder Jun 4, 2026
3cf2c5a
fix(metadata): deep copy ServiceInfo to prevent write-on-read data ra…
jieguo-coder Jun 7, 2026
9bf63a0
chore: trigger CI re-run for codecov gpg issue
jieguo-coder Jun 7, 2026
21cedcc
chore: resolve merge conflicts with develop and fix code formatting
jieguo-coder Jun 7, 2026
1bd679e
refactor(metadata): implement no-lock helper to fix data race and avo…
jieguo-coder Jun 11, 2026
c77d53a
chore: resolve merge conflict with #3369, integrating deterministic f…
jieguo-coder Jun 11, 2026
f8d3248
test: fix compilation error in instance changed listener tests by add…
jieguo-coder Jun 11, 2026
d3f571d
fix(metadata): add RLock around global map lookup in RemoveService an…
jieguo-coder Jun 13, 2026
3bf11e4
chore: resolve merge conflicts with #3370, keeping DeepCopy for concu…
jieguo-coder Jun 13, 2026
11cc932
chore: resolve test file conflict by keeping both listener and cache …
jieguo-coder Jun 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: fix failing tests and improve unit test coverage
Signed-off-by: jieguo-coder <1193249232@qq.com>
  • Loading branch information
jieguo-coder committed Jun 4, 2026
commit e65f6948a577be1666ecd491996df759d918ea22
21 changes: 21 additions & 0 deletions metadata/info/metadata_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,27 @@ func TestServiceInfoGetMatchKey(t *testing.T) {
assert.NotEmpty(t, si.GetMatchKey())
}

func TestMetadataInfoGetServices(t *testing.T) {
metadataInfo := &MetadataInfo{
Services: make(map[string]*ServiceInfo),
exportedServiceURLs: make(map[string][]*common.URL),
subscribedServiceURLs: make(map[string][]*common.URL),
}
url, _ := common.NewURL("dubbo://127.0.0.1:20000?application=foo&category=providers&check=false&dubbo=dubbo-go+v1.5.0&interface=com.foo.Bar&methods=GetPetByID%2CGetPetTypes&organization=Apache&owner=foo&revision=1.0.0&side=provider&version=1.0.0")
metadataInfo.AddService(url)

services := metadataInfo.GetServices()
require.Len(t, services, 1)
assert.NotEmpty(t, services)

// GetServices returns a copy: modifying the original does not affect the snapshot
metadataInfo.RemoveService(url)
assert.Len(t, services, 1)

// A fresh call reflects the removal
assert.Empty(t, metadataInfo.GetServices())
}

func TestServiceInfoJavaClassName(t *testing.T) {
assert.Equalf(t, "org.apache.dubbo.metadata.MetadataInfo", NewAppMetadataInfo("dubbo").JavaClassName(), "JavaClassName()")
}
33 changes: 33 additions & 0 deletions metadata/metadata_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import (
"strconv"
"sync"
"testing"
)

Expand Down Expand Up @@ -362,3 +363,35 @@
require.NoError(t, err)
})
}

func TestDefaultMetadataServiceConcurrentReadAccess(t *testing.T) {
mts := &DefaultMetadataService{
metadataMap: newMetadataMap(),
}

var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
defer wg.Done()
urls, err := mts.GetExportedServiceURLs()
require.NoError(t, err)

Check failure on line 378 in metadata/metadata_service_test.go

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest - Go 1.23)

go-require: require must only be used in the goroutine running the test function (testifylint)

Check failure on line 378 in metadata/metadata_service_test.go

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest - Go 1.23)

go-require: require must only be used in the goroutine running the test function (testifylint)
assert.NotEmpty(t, urls)
}()
wg.Add(1)
go func() {
defer wg.Done()
urls, err := mts.GetSubscribedURLs()
require.NoError(t, err)

Check failure on line 385 in metadata/metadata_service_test.go

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest - Go 1.23)

go-require: require must only be used in the goroutine running the test function (testifylint)

Check failure on line 385 in metadata/metadata_service_test.go

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest - Go 1.23)

go-require: require must only be used in the goroutine running the test function (testifylint)
assert.NotEmpty(t, urls)
}()
wg.Add(1)
go func() {
defer wg.Done()
info, err := mts.GetMetadataInfo("1")
require.NoError(t, err)

Check failure on line 392 in metadata/metadata_service_test.go

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest - Go 1.23)

go-require: require must only be used in the goroutine running the test function (testifylint)

Check failure on line 392 in metadata/metadata_service_test.go

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest - Go 1.23)

go-require: require must only be used in the goroutine running the test function (testifylint)
assert.NotNil(t, info)
}()
}
wg.Wait()
}
34 changes: 34 additions & 0 deletions metadata/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package metadata

import (
"sync"
"testing"
)

Expand Down Expand Up @@ -138,3 +139,36 @@ func TestGetMetadataService(t *testing.T) {
})
}
}

func TestAddServiceConcurrent(t *testing.T) {
var wg sync.WaitGroup
for i := 0; i < 20; i++ {
registryId := "concurrent-reg"
wg.Add(1)
go func(idx int) {
defer wg.Done()
url := common.NewURLWithOptions(
common.WithProtocol("dubbo"),
common.WithParamsValue(constant.ApplicationKey, "dubbo"),
common.WithParamsValue(constant.ApplicationTagKey, "v1"),
)
AddService(registryId, url)
}(i)
wg.Add(1)
go func(idx int) {
defer wg.Done()
url := common.NewURLWithOptions(
common.WithProtocol("dubbo"),
common.WithParamsValue(constant.ApplicationKey, "dubbo"),
common.WithParamsValue(constant.ApplicationTagKey, "v1"),
)
AddSubscribeURL(registryId, url)
}(i)
wg.Add(1)
go func(idx int) {
defer wg.Done()
_ = GetMetadataInfo(registryId)
}(i)
}
wg.Wait()
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,15 @@ func (c *capturingNotifyListener) NotifyAll(events []*registry.ServiceEvent, cal
callback()
}
}

func TestServiceInstancesChangedListenerRemoveListener(t *testing.T) {
listener := NewServiceInstancesChangedListener(testApp, gxset.NewSet(testApp)).(*ServiceInstancesChangedListenerImpl)
notify := &capturingNotifyListener{}
key := common.MatchKey(testInterface, constant.TriProtocol)

listener.AddListenerAndNotify(key, notify)
require.Len(t, listener.listeners, 1)

listener.RemoveListener(key)
require.Empty(t, listener.listeners)
}
Loading