Moved to the new go owner on my gittea so that the url to use the code is easier.

master
Zed A. Shaw 2 days ago
parent 4fe90283d3
commit fe091250bd
  1. 2
      Makefile
  2. 2
      go.mod
  3. 10
      main.go
  4. 57
      tools/cmd/tester/main.go

@ -8,7 +8,7 @@ build: build_tester
go build . go build .
test: test:
go test lcthw.dev/learn-code-the-hard-way/ozai/tests -c -o runtests$(GO_IS_STUPID_EXE) go test lcthw.dev/go/ozai/tests -c -o runtests$(GO_IS_STUPID_EXE)
./runtests$(GO_IS_STUPID_EXE) ./runtests$(GO_IS_STUPID_EXE)
build_tester: build_tester:

@ -1,4 +1,4 @@
module lcthw.dev/learn-code-the-hard-way/ozai module lcthw.dev/go/ozai
go 1.24.2 go 1.24.2

@ -5,10 +5,11 @@ import (
"os/exec" "os/exec"
"log" "log"
"io" "io"
"time"
"os" "os"
"errors" "errors"
"sync" "sync"
"lcthw.dev/learn-code-the-hard-way/ozai/config" "lcthw.dev/go/ozai/config"
) )
func LaunchLogger(in io.Reader, out io.Writer, err error) { func LaunchLogger(in io.Reader, out io.Writer, err error) {
@ -51,6 +52,13 @@ func main() {
cmd.Run() cmd.Run()
fmt.Println("WAITING for", name) fmt.Println("WAITING for", name)
go func() {
fmt.Println("killer runs")
time.Sleep(4 * time.Second)
fmt.Println("!!!!!!!!!!!!!!!!!!! TIME TO DIE!!!!!")
cmd.Process.Signal(os.Interrupt)
}()
cmd.Wait() cmd.Wait()
fmt.Println("PROC", name, "EXITED SEND QUIT") fmt.Println("PROC", name, "EXITED SEND QUIT")
} }

@ -4,8 +4,60 @@ import (
"fmt" "fmt"
"time" "time"
"flag" "flag"
"sync"
) )
func Worker(name string, done chan<- int, stop <-chan int) {
for i := 0; i < 10; i++ {
select {
case <-stop:
fmt.Println("Worker stopped:", name)
return
default:
time.Sleep(1 * time.Second)
fmt.Println("TESTER #", name)
}
}
done<- 1
}
func Supervisor(id int, count int) {
stop := make(chan int)
var wg sync.WaitGroup
for i := 0; i < count; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for {
workerDone := make(chan int)
go Worker(fmt.Sprintf("%d:%d", id, i), workerDone, stop)
select {
case <-workerDone:
fmt.Println("Supervisor: Worker Done")
time.Sleep(500 * time.Millisecond)
case <-stop:
fmt.Println("Supervisor: Stop")
return
}
}
}()
}
go func() {
// test shutdown
time.Sleep(10000 * time.Millisecond)
close(stop)
}()
wg.Wait()
}
func main() { func main() {
count := flag.Int("count", 10, "Seconds to wait") count := flag.Int("count", 10, "Seconds to wait")
id := flag.Int("id", 1, "Tester ID to use.") id := flag.Int("id", 1, "Tester ID to use.")
@ -13,8 +65,5 @@ func main() {
fmt.Println(">>> TESTER STARTS, id=", *id, "count=", *count) fmt.Println(">>> TESTER STARTS, id=", *id, "count=", *count)
for i := 0; i < *count; i++ { Supervisor(*id, *count)
time.Sleep(1 * time.Second)
fmt.Println("TESTER #", *id)
}
} }

Loading…
Cancel
Save