app_test.go 645 B

12345678910111213141516171819202122232425262728293031323334
  1. package service
  2. import (
  3. "sync"
  4. "testing"
  5. )
  6. // TestGetAppVersion
  7. func TestGetAppVersion(t *testing.T) {
  8. s := &AppService{}
  9. v := s.GetAppVersion()
  10. // 打印结果
  11. t.Logf("App Version: %s", v)
  12. }
  13. func TestMultipleGetAppVersion(t *testing.T) {
  14. s := &AppService{}
  15. //并发测试
  16. // 使用 WaitGroup 等待所有 goroutine 完成
  17. wg := sync.WaitGroup{}
  18. wg.Add(10) // 启动 10 个 goroutine
  19. // 启动 10 个 goroutine
  20. for i := 0; i < 10; i++ {
  21. go func() {
  22. defer wg.Done() // 完成后减少计数
  23. v := s.GetAppVersion()
  24. // 打印结果
  25. t.Logf("App Version: %s", v)
  26. }()
  27. }
  28. // 等待所有 goroutine 完成
  29. wg.Wait()
  30. }