engine: resources: Receive keys should match mcl, not golang
The capitalization of these keys was wrong and they weren't getting seen. Add a test as well.
This commit is contained in:
@@ -678,10 +678,10 @@ receiving one. This can _only_ be done inside of the `CheckApply` function!
|
|||||||
|
|
||||||
```golang
|
```golang
|
||||||
// inside CheckApply, probably near the top
|
// inside CheckApply, probably near the top
|
||||||
if val, exists := obj.init.Recv()["SomeKey"]; exists {
|
if val, exists := obj.init.Recv()["some_key"]; exists {
|
||||||
obj.init.Logf("the SomeKey param was sent to us from: %s.%s", val.Res, val.Key)
|
obj.init.Logf("the some_key param was sent to us from: %s.%s", val.Res, val.Key)
|
||||||
if val.Changed {
|
if val.Changed {
|
||||||
obj.init.Logf("the SomeKey param was just updated!")
|
obj.init.Logf("the some_key param was just updated!")
|
||||||
// you may want to invalidate some local cache
|
// you may want to invalidate some local cache
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1226,9 +1226,9 @@ func (obj *FileRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
|||||||
// might not have a new value to copy, and therefore we won't see this
|
// might not have a new value to copy, and therefore we won't see this
|
||||||
// notification of change. Therefore, it is important to process these
|
// notification of change. Therefore, it is important to process these
|
||||||
// promptly, if they must not be lost, such as for cache invalidation.
|
// promptly, if they must not be lost, such as for cache invalidation.
|
||||||
if val, exists := obj.init.Recv()["Content"]; exists && val.Changed {
|
if val, exists := obj.init.Recv()["content"]; exists && val.Changed {
|
||||||
// if we received on Content, and it changed, invalidate the cache!
|
// if we received on Content, and it changed, invalidate the cache!
|
||||||
obj.init.Logf("contentCheckApply: invalidating sha256sum of `Content`")
|
obj.init.Logf("contentCheckApply: invalidating sha256sum of `content`")
|
||||||
obj.sha256sum = "" // invalidate!!
|
obj.sha256sum = "" // invalidate!!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -282,9 +282,9 @@ func (obj *KVRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if val, exists := obj.init.Recv()["Value"]; exists && val.Changed {
|
if val, exists := obj.init.Recv()["value"]; exists && val.Changed {
|
||||||
// if we received on Value, and it changed, wooo, nothing to do.
|
// if we received on Value, and it changed, wooo, nothing to do.
|
||||||
obj.init.Logf("CheckApply: `Value` was updated!")
|
obj.init.Logf("CheckApply: `value` was updated!")
|
||||||
}
|
}
|
||||||
|
|
||||||
value, exists, err := obj.kvGet(ctx, obj.getKey())
|
value, exists, err := obj.kvGet(ctx, obj.getKey())
|
||||||
|
|||||||
@@ -85,9 +85,9 @@ func (obj *PrintRes) Watch(ctx context.Context) error {
|
|||||||
// CheckApply method for Print resource. Does nothing, returns happy!
|
// CheckApply method for Print resource. Does nothing, returns happy!
|
||||||
func (obj *PrintRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
func (obj *PrintRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
||||||
obj.init.Logf("CheckApply: %t", apply)
|
obj.init.Logf("CheckApply: %t", apply)
|
||||||
if val, exists := obj.init.Recv()["Msg"]; exists && val.Changed {
|
if val, exists := obj.init.Recv()["msg"]; exists && val.Changed {
|
||||||
// if we received on Msg, and it changed, log message
|
// if we received on Msg, and it changed, log message
|
||||||
obj.init.Logf("CheckApply: Received `Msg` of: %s", obj.Msg)
|
obj.init.Logf("CheckApply: Received `msg` of: %s", obj.Msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
var refresh = obj.init.Refresh()
|
var refresh = obj.init.Refresh()
|
||||||
|
|||||||
@@ -91,12 +91,13 @@ type TestRes struct {
|
|||||||
// Func1 passes the value 42 to the input and returns a string.
|
// Func1 passes the value 42 to the input and returns a string.
|
||||||
Func1 func(int) string `lang:"func1" yaml:"func1"`
|
Func1 func(int) string `lang:"func1" yaml:"func1"`
|
||||||
|
|
||||||
ValidateBool bool `lang:"validatebool" yaml:"validate_bool"` // set to true to cause a validate error
|
ValidateBool bool `lang:"validatebool" yaml:"validate_bool"` // set to true to cause a validate error
|
||||||
ValidateError string `lang:"validateerror" yaml:"validate_error"` // set to cause a validate error
|
ValidateError string `lang:"validateerror" yaml:"validate_error"` // set to cause a validate error
|
||||||
AlwaysGroup bool `lang:"alwaysgroup" yaml:"always_group"` // set to true to cause auto grouping
|
AlwaysGroup bool `lang:"alwaysgroup" yaml:"always_group"` // set to true to cause auto grouping
|
||||||
CompareFail bool `lang:"comparefail" yaml:"compare_fail"` // will compare fail?
|
CompareFail bool `lang:"comparefail" yaml:"compare_fail"` // will compare fail?
|
||||||
SendValue string `lang:"sendvalue" yaml:"send_value"` // what value should we send?
|
SendValue string `lang:"sendvalue" yaml:"send_value"` // what value should we send?
|
||||||
OnlyShow []string `lang:"onlyshow" yaml:"only_show"` // what values do we show?
|
ExpectRecv *[]string `lang:"expectrecv" yaml:"expect_recv"` // what keys should we expect from send/recv?
|
||||||
|
OnlyShow []string `lang:"onlyshow" yaml:"only_show"` // what values do we show?
|
||||||
|
|
||||||
// TODO: add more fun properties!
|
// TODO: add more fun properties!
|
||||||
|
|
||||||
@@ -146,14 +147,20 @@ func (obj *TestRes) Watch(ctx context.Context) error {
|
|||||||
|
|
||||||
// CheckApply method for Test resource. Does nothing, returns happy!
|
// CheckApply method for Test resource. Does nothing, returns happy!
|
||||||
func (obj *TestRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
func (obj *TestRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
||||||
|
expectRecv := []string{}
|
||||||
for key, val := range obj.init.Recv() {
|
for key, val := range obj.init.Recv() {
|
||||||
obj.init.Logf("CheckApply: Received `%s`, changed: %t", key, val.Changed)
|
obj.init.Logf("CheckApply: Received `%s`, changed: %t", key, val.Changed)
|
||||||
|
expectRecv = append(expectRecv, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.init.Refresh() {
|
if obj.init.Refresh() {
|
||||||
obj.init.Logf("Received a notification!")
|
obj.init.Logf("Received a notification!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if obj.ExpectRecv != nil && len(*obj.ExpectRecv) != len(expectRecv) {
|
||||||
|
return false, fmt.Errorf("the received keys differ from expected, got: %+v", expectRecv)
|
||||||
|
}
|
||||||
|
|
||||||
fakeLogf := func(format string, v ...interface{}) {
|
fakeLogf := func(format string, v ...interface{}) {
|
||||||
key := format[0:strings.LastIndex(format, ":")]
|
key := format[0:strings.LastIndex(format, ":")]
|
||||||
if len(obj.OnlyShow) == 0 || util.StrInList(key, obj.OnlyShow) {
|
if len(obj.OnlyShow) == 0 || util.StrInList(key, obj.OnlyShow) {
|
||||||
@@ -372,6 +379,19 @@ func (obj *TestRes) Cmp(r engine.Res) error {
|
|||||||
if obj.SendValue != res.SendValue {
|
if obj.SendValue != res.SendValue {
|
||||||
return fmt.Errorf("the SendValue differs")
|
return fmt.Errorf("the SendValue differs")
|
||||||
}
|
}
|
||||||
|
if (obj.ExpectRecv == nil) != (res.ExpectRecv == nil) { // xor
|
||||||
|
return fmt.Errorf("the ExpectRecv differs")
|
||||||
|
}
|
||||||
|
if obj.ExpectRecv != nil && res.ExpectRecv != nil {
|
||||||
|
if len(*obj.ExpectRecv) != len(*res.ExpectRecv) {
|
||||||
|
return fmt.Errorf("the length of ExpectRecv differs")
|
||||||
|
}
|
||||||
|
for i, x := range *obj.ExpectRecv {
|
||||||
|
if x != (*res.ExpectRecv)[i] {
|
||||||
|
return fmt.Errorf("the item at ExpectRecv index %d differs", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if len(obj.OnlyShow) != len(res.OnlyShow) {
|
if len(obj.OnlyShow) != len(res.OnlyShow) {
|
||||||
return fmt.Errorf("the length of OnlyShow differs")
|
return fmt.Errorf("the length of OnlyShow differs")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,6 +168,7 @@ func TestLowerStructFieldNameToFieldName2(t *testing.T) {
|
|||||||
"alwaysgroup": "AlwaysGroup",
|
"alwaysgroup": "AlwaysGroup",
|
||||||
"comparefail": "CompareFail",
|
"comparefail": "CompareFail",
|
||||||
"sendvalue": "SendValue",
|
"sendvalue": "SendValue",
|
||||||
|
"expectrecv": "ExpectRecv",
|
||||||
"onlyshow": "OnlyShow",
|
"onlyshow": "OnlyShow",
|
||||||
|
|
||||||
"comment": "Comment",
|
"comment": "Comment",
|
||||||
|
|||||||
@@ -126,9 +126,9 @@ func (obj *ValueRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
|||||||
received := false
|
received := false
|
||||||
different := false
|
different := false
|
||||||
checkOK := false
|
checkOK := false
|
||||||
if val, exists := obj.init.Recv()["Any"]; exists && val.Changed {
|
if val, exists := obj.init.Recv()["any"]; exists && val.Changed {
|
||||||
// if we received on Any, and it changed, invalidate the cache!
|
// if we received on Any, and it changed, invalidate the cache!
|
||||||
obj.init.Logf("CheckApply: received on `Any`")
|
obj.init.Logf("CheckApply: received on `any`")
|
||||||
obj.isSet = true // we received something
|
obj.isSet = true // we received something
|
||||||
obj.cachedAny = obj.Any
|
obj.cachedAny = obj.Any
|
||||||
received = true // we'll always need to send below when we recv
|
received = true // we'll always need to send below when we recv
|
||||||
|
|||||||
27
lang/interpret_test/TestAstFunc3/sendrecv-simple0.txtar
Normal file
27
lang/interpret_test/TestAstFunc3/sendrecv-simple0.txtar
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
-- main.mcl --
|
||||||
|
# send/recv of value1.any into test.msg works!
|
||||||
|
value "value1" {
|
||||||
|
any => "i am value1",
|
||||||
|
}
|
||||||
|
test "test1" {
|
||||||
|
sendvalue => "hello from test",
|
||||||
|
expectrecv => ["anotherstr",], # expecting to recv on these keys!
|
||||||
|
|
||||||
|
Meta:autogroup => false,
|
||||||
|
}
|
||||||
|
print "print1" {
|
||||||
|
#msg => "", # gets value from send_value above
|
||||||
|
}
|
||||||
|
Value["value1"].any -> Test["test1"].anotherstr
|
||||||
|
Test["test1"].hello -> Print["print1"].msg
|
||||||
|
-- OUTPUT --
|
||||||
|
Edge: test[test1] -> print[print1] # test[test1] -> print[print1]
|
||||||
|
Edge: value[value1] -> test[test1] # value[value1] -> test[test1]
|
||||||
|
Field: print[print1].Msg = "hello from test"
|
||||||
|
Field: test[test1].AnotherStr = "i am value1"
|
||||||
|
Field: test[test1].ExpectRecv = ["anotherstr"]
|
||||||
|
Field: test[test1].SendValue = "hello from test"
|
||||||
|
Field: value[value1].Any = "i am value1"
|
||||||
|
Vertex: print[print1]
|
||||||
|
Vertex: test[test1]
|
||||||
|
Vertex: value[value1]
|
||||||
Reference in New Issue
Block a user