diff options
author | Valery Piashchynski <[email protected]> | 2020-10-13 13:55:20 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-10-13 13:55:20 +0300 |
commit | 0dc44d54cfcc9dd3fa09a41136f35a9a8d26b994 (patch) | |
tree | ffcb65010bebe9f5b5436192979e64b2402a6ec0 /plugins/factory/tests | |
parent | 08d6b6b7f773f83b286cd48c1a0fbec9a62fb42b (diff) |
Initial commit of RR 2.0v2.0.0-alpha1
Diffstat (limited to 'plugins/factory/tests')
-rw-r--r-- | plugins/factory/tests/.rr.yaml | 9 | ||||
-rw-r--r-- | plugins/factory/tests/factory_test.go | 85 | ||||
-rw-r--r-- | plugins/factory/tests/hello.php | 1 | ||||
-rw-r--r-- | plugins/factory/tests/plugin_1.go | 55 | ||||
-rw-r--r-- | plugins/factory/tests/plugin_2.go | 88 |
5 files changed, 238 insertions, 0 deletions
diff --git a/plugins/factory/tests/.rr.yaml b/plugins/factory/tests/.rr.yaml new file mode 100644 index 00000000..171f51dc --- /dev/null +++ b/plugins/factory/tests/.rr.yaml @@ -0,0 +1,9 @@ +app: + command: "php hello.php" + user: "" + group: "" + env: + "RR_CONFIG": "/some/place/on/the/C134" + "RR_CONFIG2": "C138" + relay: "pipes" + relayTimeout: "20s"
\ No newline at end of file diff --git a/plugins/factory/tests/factory_test.go b/plugins/factory/tests/factory_test.go new file mode 100644 index 00000000..880a7cf8 --- /dev/null +++ b/plugins/factory/tests/factory_test.go @@ -0,0 +1,85 @@ +package tests + +import ( + "os" + "os/signal" + "testing" + "time" + + "github.com/spiral/endure" + "github.com/stretchr/testify/assert" + "github.com/temporalio/roadrunner-temporal/config" + "github.com/temporalio/roadrunner-temporal/factory" +) + +func TestFactory(t *testing.T) { + container, err := endure.NewContainer(endure.DebugLevel, endure.RetryOnFail(true)) + if err != nil { + t.Fatal(err) + } + // config plugin + vp := &config.ViperProvider{} + vp.Path = ".rr.yaml" + vp.Prefix = "rr" + err = container.Register(vp) + if err != nil { + t.Fatal(err) + } + + err = container.Register(&factory.App{}) + if err != nil { + t.Fatal(err) + } + + err = container.Register(&factory.WFactory{}) + if err != nil { + t.Fatal(err) + } + + err = container.Register(&Foo{}) + if err != nil { + t.Fatal(err) + } + + err = container.Register(&Foo2{}) + if err != nil { + t.Fatal(err) + } + + + err = container.Init() + if err != nil { + t.Fatal(err) + } + + errCh, err := container.Serve() + if err != nil { + t.Fatal(err) + } + + // stop by CTRL+C + c := make(chan os.Signal) + signal.Notify(c, os.Interrupt) + + tt := time.NewTicker(time.Second * 2) + + for { + select { + case e := <-errCh: + assert.NoError(t, e.Error.Err) + assert.NoError(t, container.Stop()) + return + case <-c: + er := container.Stop() + if er != nil { + panic(er) + } + return + case <-tt.C: + tt.Stop() + assert.NoError(t, container.Stop()) + return + } + } + +} diff --git a/plugins/factory/tests/hello.php b/plugins/factory/tests/hello.php new file mode 100644 index 00000000..bf9e82cc --- /dev/null +++ b/plugins/factory/tests/hello.php @@ -0,0 +1 @@ +<?php echo "hello1 - " . time();
\ No newline at end of file diff --git a/plugins/factory/tests/plugin_1.go b/plugins/factory/tests/plugin_1.go new file mode 100644 index 00000000..a7aba98e --- /dev/null +++ b/plugins/factory/tests/plugin_1.go @@ -0,0 +1,55 @@ +package tests + +import ( + "errors" + "fmt" + + "github.com/temporalio/roadrunner-temporal/config" + "github.com/temporalio/roadrunner-temporal/factory" +) + +type Foo struct { + configProvider config.Provider + spawner factory.Spawner +} + +func (f *Foo) Init(p config.Provider, spw factory.Spawner) error { + f.configProvider = p + f.spawner = spw + return nil +} + +func (f *Foo) Serve() chan error { + errCh := make(chan error, 1) + + r := &factory.AppConfig{} + err := f.configProvider.UnmarshalKey("app", r) + if err != nil { + errCh <- err + return errCh + } + + cmd, err := f.spawner.NewCmd(nil) + if err != nil { + errCh <- err + return errCh + } + if cmd == nil { + errCh <- errors.New("command is nil") + return errCh + } + a := cmd() + out, err := a.Output() + if err != nil { + errCh <- err + return errCh + } + + fmt.Println(string(out)) + + return errCh +} + +func (f *Foo) Stop() error { + return nil +} diff --git a/plugins/factory/tests/plugin_2.go b/plugins/factory/tests/plugin_2.go new file mode 100644 index 00000000..d0c3ea2c --- /dev/null +++ b/plugins/factory/tests/plugin_2.go @@ -0,0 +1,88 @@ +package tests + +import ( + "context" + "errors" + "fmt" + "time" + + "github.com/temporalio/roadrunner-temporal/config" + "github.com/temporalio/roadrunner-temporal/factory" + "github.com/temporalio/roadrunner-temporal/roadrunner" +) + +type Foo2 struct { + configProvider config.Provider + wf factory.WorkerFactory + spw factory.Spawner +} + +func (f *Foo2) Init(p config.Provider, workerFactory factory.WorkerFactory, spawner factory.Spawner) error { + f.configProvider = p + f.wf = workerFactory + f.spw = spawner + return nil +} + +func (f *Foo2) Serve() chan error { + errCh := make(chan error, 1) + + r := &factory.AppConfig{} + err := f.configProvider.UnmarshalKey("app", r) + if err != nil { + errCh <- err + return errCh + } + + cmd, err := f.spw.NewCmd(nil) + if err != nil { + errCh <- err + return errCh + } + if cmd == nil { + errCh <- errors.New("command is nil") + return errCh + } + a := cmd() + out, err := a.Output() + if err != nil { + errCh <- err + return errCh + } + + w, err := f.wf.NewWorker(context.Background(), nil) + if err != nil { + errCh <- err + return errCh + } + + _ = w + + poolConfig := &roadrunner.Config{ + NumWorkers: 10, + MaxJobs: 100, + AllocateTimeout: time.Second * 10, + DestroyTimeout: time.Second * 10, + TTL: 1000, + IdleTTL: 1000, + ExecTTL: time.Second * 10, + MaxPoolMemory: 10000, + MaxWorkerMemory: 10000, + } + + pool, err := f.wf.NewWorkerPool(context.Background(), poolConfig, nil) + if err != nil { + errCh <- err + return errCh + } + + _ = pool + + fmt.Println(string(out)) + + return errCh +} + +func (f *Foo2) Stop() error { + return nil +} |