-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
62 changed files
with
16,208 additions
and
1,411 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
!**/*.svg | ||
!**/*.sh | ||
!**/ | ||
!./test/* | ||
!**/.vscode/* | ||
|
||
!/.gitignore | ||
!/go.mod | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
// Utilisez IntelliSense pour en savoir plus sur les attributs possibles. | ||
// Pointez pour afficher la description des attributs existants. | ||
// Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Attach to Process", | ||
"type": "go", | ||
"request": "attach", | ||
"mode": "local", | ||
"processId": "${command:pickGoProcess}" | ||
}, | ||
{ | ||
"name": "Launch Package", | ||
"type": "go", | ||
"preLaunchTask": "DeleteFolder", | ||
"request": "launch", | ||
"mode": "auto", | ||
"program": "./test", | ||
"args": [ | ||
"4", | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "MultiProcesses_prep", | ||
"type": "shell", | ||
"command": "./test/multiProcesses_prep.sh", | ||
"problemMatcher": [] | ||
}, | ||
{ | ||
"label": "DeleteFolder", | ||
"type": "shell", | ||
"command": "rm -rf ~/.shoset", | ||
"problemMatcher": [] | ||
}, | ||
{ | ||
"label": "RunMultiProcesses", | ||
"runOptions": {}, | ||
"dependsOrder": "sequence", | ||
"dependsOn": [ | ||
"MultiProcesses_prep", | ||
"RunMultiProcesses_run" | ||
], | ||
"problemMatcher": [] | ||
}, | ||
{ | ||
"label": "RunMultiProcesses_run", | ||
"runOptions": {}, | ||
"dependsOrder": "parallel", | ||
"dependsOn": [ | ||
"RunMultiProcesses_E", | ||
"RunMultiProcesses_D", | ||
"RunMultiProcesses_C", | ||
"RunMultiProcesses_B", | ||
"RunMultiProcesses_A" | ||
], | ||
"problemMatcher": [ | ||
"$go" | ||
] | ||
}, | ||
{ | ||
"label": "RunMultiProcesses_A", | ||
"type": "shell", | ||
"command": "./test/multiProcesses_A.sh", | ||
"presentation": { | ||
"group": "test" | ||
} | ||
}, | ||
{ | ||
"label": "RunMultiProcesses_B", | ||
"type": "shell", | ||
"command": "./test/multiProcesses_B.sh", | ||
"presentation": { | ||
"group": "test" | ||
} | ||
}, | ||
{ | ||
"label": "RunMultiProcesses_C", | ||
"type": "shell", | ||
"command": "./test/multiProcesses_C.sh", | ||
"presentation": { | ||
"group": "test" | ||
} | ||
}, | ||
{ | ||
"label": "RunMultiProcesses_D", | ||
"type": "shell", | ||
"command": "./test/multiProcesses_D.sh", | ||
"presentation": { | ||
"group": "test" | ||
} | ||
}, | ||
{ | ||
"label": "RunMultiProcesses_E", | ||
"type": "shell", | ||
"command": "./test/multiProcesses_E.sh", | ||
"presentation": { | ||
"group": "test" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package concurentData | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"sync" | ||
"time" | ||
|
||
eventBus "github.com/ditrit/shoset/event_bus" | ||
) | ||
|
||
// This is a thread safe slice that allows you to wait for the next change or for it to be empty. | ||
type ConcurentSlice struct { | ||
sliceValues []string | ||
eventBus eventBus.EventBus // topics : change, empty (value not used) | ||
m sync.RWMutex | ||
} | ||
|
||
func NewConcurentSlice() ConcurentSlice { | ||
return ConcurentSlice{eventBus: eventBus.NewEventBus()} | ||
} | ||
|
||
// Appends data to the slice and publishes the change event. | ||
func (cSlice *ConcurentSlice) AppendToConcurentSlice(data string) { | ||
cSlice.m.Lock() | ||
defer cSlice.m.Unlock() | ||
|
||
cSlice.sliceValues = append(cSlice.sliceValues, data) | ||
cSlice.eventBus.Publish("change", true) | ||
} | ||
|
||
// Deletes data from the slice and publishes the change (and empty) event. | ||
func (cSlice *ConcurentSlice) DeleteFromConcurentSlice(data string) { | ||
cSlice.m.Lock() | ||
defer cSlice.m.Unlock() | ||
|
||
for i, a := range cSlice.sliceValues { | ||
if a == data { | ||
// Deletes data from the slice in an efficient way (avoids moving remaining data). | ||
cSlice.sliceValues[i] = cSlice.sliceValues[len(cSlice.sliceValues)-1] | ||
cSlice.sliceValues = cSlice.sliceValues[:len(cSlice.sliceValues)-1] | ||
|
||
cSlice.eventBus.Publish("change", true) | ||
|
||
if len(cSlice.sliceValues) == 0 { | ||
cSlice.eventBus.Publish("empty", true) | ||
} | ||
return | ||
} | ||
} | ||
} | ||
|
||
// Waits for the Slice to be empty | ||
func (cSlice *ConcurentSlice) WaitForEmpty(timeout int) error { | ||
cSlice.m.RLock() | ||
if len(cSlice.sliceValues) != 0 { | ||
// Subscribes a channel to the empty topic : | ||
chEmpty := make(chan interface{}) | ||
cSlice.eventBus.Subscribe("empty", chEmpty) | ||
defer cSlice.eventBus.UnSubscribe("empty", chEmpty) | ||
|
||
cSlice.m.RUnlock() | ||
select { | ||
case <-chEmpty: | ||
return nil | ||
case <-time.After(time.Duration(timeout) * time.Second): | ||
return errors.New("the list is no empty (timeout)") | ||
} | ||
} | ||
cSlice.m.RUnlock() | ||
return nil | ||
} | ||
|
||
// Wait for the Slice to change | ||
func (cSlice *ConcurentSlice) WaitForChange(timeout int) error { | ||
cSlice.m.RLock() | ||
|
||
// Subscribes a channel to the change topic : | ||
chChange := make(chan interface{}) | ||
cSlice.eventBus.Subscribe("change", chChange) | ||
defer cSlice.eventBus.UnSubscribe("change", chChange) | ||
|
||
cSlice.m.RUnlock() | ||
select { | ||
case <-chChange: | ||
return nil | ||
case <-time.After(time.Duration(timeout) * time.Second): | ||
return errors.New("the list did not change (timeout)") | ||
} | ||
} | ||
|
||
func (cSlice *ConcurentSlice) Contains(data string) bool { | ||
// contains range through a slice to search for a particular string | ||
for _, v := range cSlice.sliceValues { | ||
if v == data { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func (cSlice *ConcurentSlice) String() string { | ||
cSlice.m.RLock() | ||
defer cSlice.m.RUnlock() | ||
return fmt.Sprint(cSlice.sliceValues) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package concurentData | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func Test_concurentSlice(t *testing.T) { | ||
cSlice := NewConcurentSlice() | ||
|
||
number := 10 //Changing this requires updating the strings the result is compared to. | ||
|
||
go func() { | ||
for { | ||
cSlice.WaitForChange(5) | ||
fmt.Println("Change received.") | ||
} | ||
}() | ||
|
||
time.Sleep(10 * time.Millisecond) | ||
|
||
for i := 0; i < number; i++ { | ||
cSlice.AppendToConcurentSlice("Test " + fmt.Sprint(i)) | ||
} | ||
if !cSlice.Contains("Test 0") { | ||
t.Errorf("Wrong content after appending.") | ||
} | ||
if cSlice.String() != "[Test 0 Test 1 Test 2 Test 3 Test 4 Test 5 Test 6 Test 7 Test 8 Test 9]" { | ||
t.Errorf("Wrong content after appending.") | ||
} | ||
fmt.Println(cSlice.String()) | ||
|
||
for i := 0; i < number-(number/2); i++ { | ||
cSlice.DeleteFromConcurentSlice("Test " + fmt.Sprint(i)) | ||
} | ||
if cSlice.String() != "[Test 9 Test 8 Test 7 Test 6 Test 5]" { | ||
t.Errorf("Wrong content after Clearing.") | ||
} | ||
fmt.Println(cSlice.String()) | ||
|
||
var wg sync.WaitGroup | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
for i := 0; i < number-(number/2); i++ { | ||
cSlice.AppendToConcurentSlice("Test " + fmt.Sprint(i)) | ||
} | ||
}() | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
for i := 5; i < number; i++ { | ||
cSlice.DeleteFromConcurentSlice("Test " + fmt.Sprint(i)) | ||
} | ||
}() | ||
|
||
wg.Wait() | ||
|
||
go func() { | ||
for i := 0; i < number-(number/2); i++ { | ||
cSlice.DeleteFromConcurentSlice("Test " + fmt.Sprint(i)) | ||
fmt.Println(cSlice.String()) | ||
time.Sleep(10 * time.Millisecond) | ||
} | ||
}() | ||
|
||
cSlice.WaitForEmpty(5) | ||
|
||
if cSlice.String() != "[]" { | ||
t.Errorf("Wrong content after Clearing.") | ||
} | ||
|
||
fmt.Println(cSlice.String()) | ||
|
||
cSlice.AppendToConcurentSlice("TEST") | ||
|
||
err := cSlice.WaitForEmpty(5) | ||
|
||
if err == nil { | ||
t.Errorf("Timeout error failed.") | ||
} | ||
} |
Oops, something went wrong.
284c831
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changelog :
For the rest of the changes, see branch new_pki.
Refacto of the test folder to have multiples files in multiple packages :
run_shoset.sh
) to avoid using aliases to clear the.shoset
folder before testing.Data race elimination :
Acknowledge on join and link to know when the connection is ready. (Move storage of the connection after the acknowledge is received.
Add protocol field to shosetConn.
Change in the behaviour of the configuration storage :
cert_checker.sh
(not fully working).mapsyncmap : Generic accessor for append, get and delete.
config : Generic accessor for append and delete.
Generic function for receiving (Wait) and sending (Send) a message of any type (for which the speceific fonctions are defined).
Event bus :
Routing system :
const.go :
Various list of message types to define which can do what. (See guide on how to create a new message type.)
Script to generate class diagram and call diagram. (see guide)
CPU/memory profiler and tracer.