mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-16 10:08:12 +02:00
[management] Add transaction to addPeer (#2469)
This PR removes the GetAccount and SaveAccount operations from the AddPeer and instead makes use of gorm.Transaction to add the new peer.
This commit is contained in:
@ -627,7 +627,7 @@ func testSyncStatusRace(t *testing.T) {
|
||||
}
|
||||
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
peer, err := am.Store.GetPeerByPeerPubKey(context.Background(), peerWithInvalidStatus.PublicKey().String())
|
||||
peer, err := am.Store.GetPeerByPeerPubKey(context.Background(), LockingStrengthShare, peerWithInvalidStatus.PublicKey().String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
@ -638,8 +638,8 @@ func testSyncStatusRace(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_LoginPerformance(t *testing.T) {
|
||||
if os.Getenv("CI") == "true" {
|
||||
t.Skip("Skipping on CI")
|
||||
if os.Getenv("CI") == "true" || runtime.GOOS == "windows" {
|
||||
t.Skip("Skipping test on CI or Windows")
|
||||
}
|
||||
|
||||
t.Setenv("NETBIRD_STORE_ENGINE", "sqlite")
|
||||
@ -655,7 +655,7 @@ func Test_LoginPerformance(t *testing.T) {
|
||||
// {"M", 250, 1},
|
||||
// {"L", 500, 1},
|
||||
// {"XL", 750, 1},
|
||||
{"XXL", 2000, 1},
|
||||
{"XXL", 5000, 1},
|
||||
}
|
||||
|
||||
log.SetOutput(io.Discard)
|
||||
@ -700,15 +700,18 @@ func Test_LoginPerformance(t *testing.T) {
|
||||
}
|
||||
defer mgmtServer.GracefulStop()
|
||||
|
||||
t.Logf("management setup complete, start registering peers")
|
||||
|
||||
var counter int32
|
||||
var counterStart int32
|
||||
var wg sync.WaitGroup
|
||||
var wgAccount sync.WaitGroup
|
||||
var mu sync.Mutex
|
||||
messageCalls := []func() error{}
|
||||
for j := 0; j < bc.accounts; j++ {
|
||||
wg.Add(1)
|
||||
wgAccount.Add(1)
|
||||
var wgPeer sync.WaitGroup
|
||||
go func(j int, counter *int32, counterStart *int32) {
|
||||
defer wg.Done()
|
||||
defer wgAccount.Done()
|
||||
|
||||
account, err := createAccount(am, fmt.Sprintf("account-%d", j), fmt.Sprintf("user-%d", j), fmt.Sprintf("domain-%d", j))
|
||||
if err != nil {
|
||||
@ -722,7 +725,9 @@ func Test_LoginPerformance(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
startTime := time.Now()
|
||||
for i := 0; i < bc.peers; i++ {
|
||||
wgPeer.Add(1)
|
||||
key, err := wgtypes.GeneratePrivateKey()
|
||||
if err != nil {
|
||||
t.Logf("failed to generate key: %v", err)
|
||||
@ -763,21 +768,29 @@ func Test_LoginPerformance(t *testing.T) {
|
||||
mu.Lock()
|
||||
messageCalls = append(messageCalls, login)
|
||||
mu.Unlock()
|
||||
_, _, _, err = am.LoginPeer(context.Background(), peerLogin)
|
||||
if err != nil {
|
||||
t.Logf("failed to login peer: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
atomic.AddInt32(counterStart, 1)
|
||||
if *counterStart%100 == 0 {
|
||||
t.Logf("registered %d peers", *counterStart)
|
||||
}
|
||||
go func(peerLogin PeerLogin, counterStart *int32) {
|
||||
defer wgPeer.Done()
|
||||
_, _, _, err = am.LoginPeer(context.Background(), peerLogin)
|
||||
if err != nil {
|
||||
t.Logf("failed to login peer: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
atomic.AddInt32(counterStart, 1)
|
||||
if *counterStart%100 == 0 {
|
||||
t.Logf("registered %d peers", *counterStart)
|
||||
}
|
||||
}(peerLogin, counterStart)
|
||||
|
||||
}
|
||||
wgPeer.Wait()
|
||||
|
||||
t.Logf("Time for registration: %s", time.Since(startTime))
|
||||
}(j, &counter, &counterStart)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
wgAccount.Wait()
|
||||
|
||||
t.Logf("prepared %d login calls", len(messageCalls))
|
||||
testLoginPerformance(t, messageCalls)
|
||||
|
Reference in New Issue
Block a user