You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
896 B

  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "log"
  6. "os"
  7. "os/signal"
  8. "sync"
  9. "time"
  10. "github.com/hermeznetwork/hermez-node/test/proofserver"
  11. )
  12. func main() {
  13. var addr string
  14. flag.StringVar(&addr, "a", "localhost:3000", "listen address")
  15. var provingDuration time.Duration
  16. flag.DurationVar(&provingDuration, "d", 2*time.Second, "proving time duration") //nolint:gomnd
  17. flag.Parse()
  18. mock := proofserver.NewMock(addr, provingDuration)
  19. ctx, cancel := context.WithCancel(context.Background())
  20. var wg sync.WaitGroup
  21. wg.Add(1)
  22. go func() {
  23. if err := mock.Run(ctx); err != nil {
  24. log.Fatal(err)
  25. }
  26. wg.Done()
  27. }()
  28. stopCh := make(chan interface{})
  29. // catch ^C to send the stop signal
  30. ossig := make(chan os.Signal, 1)
  31. signal.Notify(ossig, os.Interrupt)
  32. go func() {
  33. for sig := range ossig {
  34. if sig == os.Interrupt {
  35. stopCh <- nil
  36. }
  37. }
  38. }()
  39. <-stopCh
  40. cancel()
  41. wg.Wait()
  42. }