Skip to content

Commit

Permalink
This is to make sure activations for a shared action run in an invoca…
Browse files Browse the repository at this point in the history
…tion namespace. (#5296)
  • Loading branch information
style95 authored Jul 29, 2022
1 parent f29981a commit 44379b8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/src/test/scala/common/WskTestHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ object ActivationResponse extends DefaultJsonProtocol {
* @param annotations a list of JSON objects to save the annotations of the activation
*/
case class ActivationResult(activationId: String,
namespace: String,
logs: Option[List[String]],
response: ActivationResponse,
start: Instant,
Expand Down Expand Up @@ -123,14 +124,14 @@ object ActivationResult extends DefaultJsonProtocol {
}

implicit val serdes = new RootJsonFormat[ActivationResult] {
private val format = jsonFormat8(ActivationResult.apply)
private val format = jsonFormat9(ActivationResult.apply)

def write(result: ActivationResult) = format.write(result)

def read(value: JsValue) = {
val obj = value.asJsObject
obj.getFields("activationId", "response", "start") match {
case Seq(JsString(activationId), response, start) =>
obj.getFields("activationId", "namespace", "response", "start") match {
case Seq(JsString(activationId), JsString(namespace), response, start) =>
Try {
val logs = obj.fields.get("logs").map(_.convertTo[List[String]])
val end = obj.fields.get("end").map(_.convertTo[Instant]).getOrElse(Instant.EPOCH)
Expand All @@ -139,6 +140,7 @@ object ActivationResult extends DefaultJsonProtocol {
val annotations = obj.fields.get("annotations").map(_.convertTo[List[JsObject]])
new ActivationResult(
activationId,
namespace,
logs,
response.convertTo[ActivationResponse],
start.convertTo[Instant],
Expand Down
28 changes: 28 additions & 0 deletions tests/src/test/scala/system/basic/WskActivationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,32 @@ class WskActivationTests extends TestHelpers with WskTestHelpers with WskActorSy
resultWithoutSize shouldBe expectedResult
}
}

it should "invoke a shared action under a different invocation namespace" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>
val packageName = "shared-package"
val actionName = "echo"
var invocationNamesapce = if (wskprops.namespace == "_") "guest" else wskprops.namespace
val packageActionName = s"/${invocationNamesapce}/${packageName}/${actionName}"

assetHelper.withCleaner(wsk.pkg, packageName) { (pkg, _) =>
pkg.create(packageName, shared = Some(true))(wp)
}

assetHelper.withCleaner(wsk.action, packageActionName) { (action, _) =>
action.create(packageActionName, Some(TestUtils.getTestActionFilename("echo.js")))(wp)
}

withActivation(wsk.activation, wsk.action.invoke(packageActionName)(wp)) { activation =>
activation.namespace shouldBe invocationNamesapce
}(wp)

val systemId = "whisk.system"
val wskprops2 = WskProps(authKey = WskAdmin.listKeys(systemId)(0)._1, namespace = systemId)
invocationNamesapce = if (wskprops2.namespace == "_") "guest" else wskprops2.namespace

withActivation(wsk.activation, wsk.action.invoke(packageActionName)(wskprops2)) { activation =>
activation.namespace shouldBe invocationNamesapce
}(wskprops2)
}
}

0 comments on commit 44379b8

Please sign in to comment.