1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package mjs
- import (
- "errors"
- "fmt"
- "io/ioutil"
- "log"
- "os"
- "testing"
- "time"
- "github.com/dop251/goja"
- )
- var contentPath = "content"
- func filePath(name string) string {
- return fmt.Sprintf("%v/%v", contentPath, name)
- }
- func modified(name string) (res int64) {
- if info, err := os.Stat(filePath(name)); err == nil {
- res = info.ModTime().Unix()
- }
- return
- }
- func content(name string) ([]byte, error) {
- return ioutil.ReadFile(filePath(name))
- }
- func TestMJS(t *testing.T) {
- mjs := New(modified, content)
- for i := 0; i < 20; i++ {
- modified, err := mjs.Exec("main", map[string]interface{}{
- "flush": func(args ...interface{}) {
- log.Println(args)
- },
- }, time.Second*300)
- t.Log(err, err == nil, modified)
- }
- }
- type CallResult struct {
- }
- func Call(runtime *goja.Runtime, call goja.Callable) {
- log.Println("CALL_START", runtime, call)
- if call == nil {
- log.Println(errors.New("OKKO"))
- log.Println("CALL_FINIFH - nil")
- return
- }
- result, err := call(goja.Undefined())
- log.Println("CALL_FINIFH - nil", result, err)
- //return errors.New("ERRRRROR")
- }
- func TestInterrupt(t *testing.T) {
- mjs := New(modified, content)
- for i := 0; i < 2; i++ {
- modified, err := mjs.Exec("interrupt", map[string]interface{}{
- "call": Call,
- "flush": func(args ...interface{}) {
- log.Println(args)
- },
- }, time.Second*5)
- t.Log(err, err == nil, modified)
- }
- time.Sleep(time.Second * 10)
- }
|