File: race_test.go

package info (click to toggle)
golang-layeh-gopher-luar 1.0.4-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 224 kB
  • sloc: makefile: 7
file content (42 lines) | stat: -rw-r--r-- 618 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// +build race

package luar

import (
	"runtime"
	"testing"

	"github.com/yuin/gopher-lua"
)

func Test_functhread(t *testing.T) {
	L := lua.NewState()
	defer L.Close()

	var fn func(x int) string
	L.SetGlobal("fn", New(L, &fn))

	if err := L.DoString(`_ = fn ^ function(x) return tostring(x) .. "!"  end`); err != nil {
		t.Fatal(err)
	}

	done := make(chan struct{})
	defer close(done)
	go func() {
		for {
			select {
			case <-done:
				return
			default:
			}

			L.Push(lua.LNumber(1000))

			runtime.Gosched()
		}
	}()

	if ret := fn(123); ret != "123!" {
		t.Fatalf("expected %#v, got %#v", "123!", ret)
	}
}