1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2024-12-14 12:37:31 +00:00

added concurrent test

This commit is contained in:
postmannen 2022-05-10 06:57:07 +02:00
parent 304436a220
commit 85a7124bf3

View file

@ -3,8 +3,10 @@ package main
import (
"bytes"
"flag"
"fmt"
"io"
"log"
"sync"
"testing"
"github.com/fxamacker/cbor/v2"
@ -243,3 +245,46 @@ func TestHash(t *testing.T) {
t.Fatalf(" \U0001F631 [FAILED]: hash mismatch")
}
}
func TestACLConcurrent(t *testing.T) {
c := newCentralAuth()
// -----------General testing and creation of some data----------------
// Start concurrent updating of the schema.
var wg sync.WaitGroup
for i := 0; i < 4000; i++ {
wg.Add(1)
go func() {
defer wg.Done()
c.authorization.authSchema.aclAdd("ship1", "operator2", "rm -rf")
c.authorization.authSchema.aclAdd("ship1", "operator1", "ls -lt")
c.authorization.authSchema.aclAdd("ship1", "operator1", "ls -lt")
c.authorization.authSchema.aclAdd("ship1", "operator2", "ls -l")
c.authorization.authSchema.aclAdd("ship3", "operator3", "ls -lt")
c.authorization.authSchema.aclAdd("ship3", "operator3", "vi /etc/hostname")
c.authorization.authSchema.aclDeleteCommand("ship3", "operator2", "ls -lt")
c.authorization.authSchema.aclDeleteSource("ship3", "operator3")
}()
wg.Add(1)
go func() {
defer wg.Done()
// fmt.Println("----schemaMain------")
c.authorization.authSchema.schemaMain.mu.Lock()
for _, v := range c.authorization.authSchema.schemaMain.ACLMap {
_ = fmt.Sprintf("%+v\n", v)
}
c.authorization.authSchema.schemaMain.mu.Unlock()
// fmt.Println("----schemaGenerated------")
c.authorization.authSchema.schemaGenerated.mu.Lock()
for k, v := range c.authorization.authSchema.schemaGenerated.GeneratedACLsMap {
_ = fmt.Sprintf("node: %v, NodeDataSerialized: %v\n", k, string(v.Data))
_ = fmt.Sprintf("node: %v, Hash: %v\n", k, v.Hash)
}
c.authorization.authSchema.schemaGenerated.mu.Unlock()
}()
}
wg.Wait()
}