fix(compiler): Do not generate hop back with empty response by default [LNG-305] (#1019)

Change default flag, add test
This commit is contained in:
InversionSpaces 2023-12-21 12:17:50 +01:00 committed by GitHub
parent 5bc01a9c02
commit a4d8ee7083
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 1 deletions

View File

@ -11,7 +11,7 @@ case class AquaAPIConfig(
noXor: Boolean = false, // TODO: Remove noXor: Boolean = false, // TODO: Remove
noRelay: Boolean = false, noRelay: Boolean = false,
tracing: Boolean = false, tracing: Boolean = false,
noEmptyResponse: Boolean = false noEmptyResponse: Boolean = true
) { ) {
def getTransformConfig: TransformConfig = { def getTransformConfig: TransformConfig = {

View File

@ -221,6 +221,69 @@ class AquaCompilerSpec extends AnyFlatSpec with Matchers with Inside {
} }
} }
it should "not generate hop back with empty response" in {
val src = Map(
"index.aqua" ->
"""service Op("op"):
| call(s: string)
|
|func exec(peers: []string):
| for peer <- peers par:
| on peer:
| Op.call("hahahahah")
|""".stripMargin
)
val transformCfg = TransformConfig(
noEmptyResponse = true
)
insideRes(src, transformCfg = transformCfg)("exec") { case exec :: _ =>
val peers = VarModel("-peers-arg-", ArrayType(ScalarType.string))
val peer = VarModel("peer-0", ScalarType.string)
val initPeer = LiteralModel.fromRaw(ValueRaw.InitPeerId)
val expected =
XorRes.wrap(
SeqRes.wrap(
getDataSrv("-relay-", "-relay-", ScalarType.string),
getDataSrv("peers", peers.name, peers.`type`),
ParRes.wrap(
FoldRes
.lastNever(peer.name, peers)
.wrap(
ParRes.wrap(
XorRes.wrap(
SeqRes.wrap(
through(ValueModel.fromRaw(relay)),
CallServiceRes(
LiteralModel.fromRaw(LiteralRaw.quote("op")),
"call",
CallRes(
LiteralModel.fromRaw(LiteralRaw.quote("hahahahah")) :: Nil,
None
),
peer
).leaf
),
SeqRes.wrap(
through(ValueModel.fromRaw(relay)),
through(initPeer),
failErrorRes
)
),
NextRes(peer.name).leaf
)
)
)
),
errorCall(transformCfg, 0, initPeer)
)
exec.body.equalsOrShowDiff(expected) shouldBe (true)
}
}
it should "compile with imports" in { it should "compile with imports" in {
val src = Map( val src = Map(