mirror of
https://github.com/postmannen/ctrl.git
synced 2025-01-05 20:09:16 +00:00
added concurrent test
This commit is contained in:
parent
304436a220
commit
85a7124bf3
1 changed files with 45 additions and 0 deletions
|
@ -3,8 +3,10 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/fxamacker/cbor/v2"
|
"github.com/fxamacker/cbor/v2"
|
||||||
|
@ -243,3 +245,46 @@ func TestHash(t *testing.T) {
|
||||||
t.Fatalf(" \U0001F631 [FAILED]: hash mismatch")
|
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()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue