v1.1.0 : Multithreading & UX update
This commit is contained in:
@@ -26,7 +26,7 @@ func (m *manager) parseConfig() bool {
|
||||
fmt.Printf("\nUnable to deserialize config file: %s\n", err)
|
||||
return false
|
||||
}
|
||||
fmt.Println("Configuration file successfully loaded\n")
|
||||
fmt.Println("Configuration file successfully loaded")
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
// Launch it via goroutine
|
||||
// Start read log of service
|
||||
func readLog(service *Service, reader io.ReadCloser) {
|
||||
scanner := bufio.NewScanner(reader)
|
||||
for scanner.Scan() {
|
||||
str := scanner.Text()
|
||||
if service.Console {
|
||||
fmt.Printf("[%s] %s\n", service.Path, str)
|
||||
}
|
||||
fmt.Printf("%s\n", str)
|
||||
service.Mutex.Lock()
|
||||
service.Logs = append(service.Logs, str)
|
||||
service.Mutex.Unlock()
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
fmt.Printf("[%s] Service failed: %s\n", service.Path, err)
|
||||
}
|
||||
fmt.Printf("Logger of service: [%s] stopped\n", service.Path)
|
||||
service.Active = false
|
||||
}
|
||||
+19
-18
@@ -6,38 +6,39 @@ import (
|
||||
)
|
||||
|
||||
type manager struct {
|
||||
Config
|
||||
Config
|
||||
|
||||
Tests []Result
|
||||
Result *TestCase
|
||||
DB mysql_db
|
||||
Tests []Result
|
||||
Result *TestCase
|
||||
DB mysql_db
|
||||
}
|
||||
|
||||
// Config needs refacto
|
||||
type Config struct {
|
||||
Cameradar Service `json:"Cameradar"`
|
||||
Cameradar Service `json:"Cameradar"`
|
||||
|
||||
Output string
|
||||
Output string
|
||||
}
|
||||
|
||||
func (m *manager) Init() bool {
|
||||
fmt.Println("- Parsing")
|
||||
if !m.parseConfig() {
|
||||
return false
|
||||
}
|
||||
fmt.Println("- Parsing")
|
||||
if !m.parseConfig() {
|
||||
return false
|
||||
}
|
||||
|
||||
fmt.Println("- Cleaning content")
|
||||
killService(&m.Config.Cameradar)
|
||||
fmt.Println("- Cleaning content")
|
||||
killService(&m.Config.Cameradar)
|
||||
|
||||
return true
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *manager) Run() bool {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
fmt.Println("\n- Launching all tests")
|
||||
fmt.Println("\n- Launching all tests")
|
||||
var newTest = new(TestCase)
|
||||
newTest.expected = m.Tests
|
||||
if (m.generateConfig(m.Tests, &m.DB)) {
|
||||
if m.generateConfig(m.Tests, &m.DB) {
|
||||
m.dropDB()
|
||||
wg.Add(1)
|
||||
go m.invokeTestCase(newTest, &wg)
|
||||
@@ -49,6 +50,6 @@ func (m *manager) Run() bool {
|
||||
}
|
||||
|
||||
func (m *manager) Stop() bool {
|
||||
killService(&m.Config.Cameradar)
|
||||
return true
|
||||
}
|
||||
killService(&m.Config.Cameradar)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Service needs refacto
|
||||
type Service struct {
|
||||
Path string `json:"Path"`
|
||||
Args string `json:"Args"`
|
||||
|
||||
+15
-10
@@ -4,29 +4,32 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
"net"
|
||||
)
|
||||
|
||||
type mysql_db struct {
|
||||
// MysqlDB needs refacto
|
||||
type MysqlDB struct {
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
User string `json:"user"`
|
||||
Password string `json:"password"`
|
||||
Db_name string `json:"db_name"`
|
||||
DbName string `json:"db_name"`
|
||||
}
|
||||
|
||||
// CameradarConfig needs refacto
|
||||
type CameradarConfig struct {
|
||||
Mysql_db mysql_db `json:"mysql_db"`
|
||||
Subnets string `json:"subnets"`
|
||||
Ports string `json:"ports"`
|
||||
Rtsp_url_file string `json:"rtsp_url_file"`
|
||||
Rtsp_ids_file string `json:"rtsp_ids_file"`
|
||||
Thumbnail_storage_path string `json:"thumbnail_storage_path"`
|
||||
MysqlDB MysqlDB `json:"mysql_db"`
|
||||
Subnets string `json:"subnets"`
|
||||
Ports string `json:"ports"`
|
||||
RtspURLFile string `json:"rtsp_url_file"`
|
||||
RtspIdsFile string `json:"rtsp_ids_file"`
|
||||
ThumbnailStoragePath string `json:"thumbnail_storage_path"`
|
||||
}
|
||||
|
||||
// Result needs refacto
|
||||
type Result struct {
|
||||
Address string `json:"address"`
|
||||
Password string `json:"password"`
|
||||
@@ -37,6 +40,7 @@ type Result struct {
|
||||
Thumb string `json:"thumbnail_path,omitempty"`
|
||||
}
|
||||
|
||||
// TestCase needs refacto
|
||||
type TestCase struct {
|
||||
expected []Result
|
||||
result []Result
|
||||
@@ -82,7 +86,7 @@ func (m *manager) runTestCase(test *TestCase) bool {
|
||||
for _, e := range test.expected {
|
||||
e.Thumb = r.Thumb
|
||||
var err error
|
||||
var addr[] string
|
||||
var addr []string
|
||||
addr, err = net.LookupHost(e.Address)
|
||||
e.Address = addr[0]
|
||||
if e == r {
|
||||
@@ -153,6 +157,7 @@ func (m *manager) generateConfig(test []Result, DataBase *mysql_db) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Extend needs refacto
|
||||
func Extend(slice []Result, element Result) []Result {
|
||||
n := len(slice)
|
||||
if n == cap(slice) {
|
||||
|
||||
@@ -107,6 +107,9 @@ func (m *manager) writeJUnitReportXML(result TestCase, r io.ReadWriter, output s
|
||||
// Write in param stream
|
||||
|
||||
w, err := os.OpenFile(output, os.O_WRONLY|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
writer := io.Writer(w)
|
||||
writer.Write(bytes)
|
||||
|
||||
@@ -131,7 +134,7 @@ func (m *manager) writeConsoleReport(result TestCase) bool {
|
||||
} else {
|
||||
failureCount++
|
||||
}
|
||||
fmt.Println("--- Test summary ---\n")
|
||||
fmt.Println("--- Test summary ---")
|
||||
if successCount > 0 {
|
||||
fmt.Printf("Results: %d/%d (%d%%)\n", successCount, successCount+failureCount, successCount*100/(successCount+failureCount))
|
||||
fmt.Printf("Total time: %.6fs\n", total.Seconds())
|
||||
|
||||
Reference in New Issue
Block a user