Skip to content

Commit dbea286

Browse files
Fix tests
1 parent 2ace98b commit dbea286

6 files changed

Lines changed: 54 additions & 28 deletions

File tree

common/scala/src/main/scala/org/apache/openwhisk/core/entity/WhiskAction.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,7 @@ object WhiskAction extends DocumentFactory[WhiskAction] with WhiskEntityQueries[
490490
old)
491491
}
492492
} match {
493-
case Success(f) =>
494-
implicit val ec = db.executionContext
495-
implicit val logger = db.logging
496-
WhiskActionVersionList.deleteCache(doc.fullyQualifiedName(false))
497-
f
493+
case Success(f) => f
498494
case Failure(f) => Future.failed(f)
499495
}
500496
}

core/controller/src/main/scala/org/apache/openwhisk/core/controller/Actions.scala

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
234234
case Success(id) =>
235235
putEntity(WhiskAction, entityStore, id, true, update(user, request) _, () => {
236236
make(user, entityName, request)
237+
}, postProcess = Some { action: WhiskAction =>
238+
WhiskActionVersionList.deleteCache(entityName)
239+
complete(OK, action)
237240
})
238241
case Failure(f) =>
239242
terminate(InternalServerError)
@@ -354,11 +357,18 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
354357
parameter('version.as[SemVer] ?) { version =>
355358
onComplete(WhiskActionVersionList.get(entityName, entityStore)) {
356359
case Success(results) =>
357-
WhiskActionVersionList.deleteCache(entityName) // invalidate version list cache at all cases
358360
version match {
359361
case Some(_) =>
360362
val docId = results.matchedDocId(version).getOrElse(entityName.toDocId)
361-
deleteEntity(WhiskAction, entityStore, docId, (a: WhiskAction) => Future.successful({}))
363+
deleteEntity(
364+
WhiskAction,
365+
entityStore,
366+
docId,
367+
(a: WhiskAction) => Future.successful({}),
368+
postProcess = Some { action: WhiskAction =>
369+
WhiskActionVersionList.deleteCache(entityName)
370+
complete(OK, action)
371+
})
362372
case None =>
363373
val fs =
364374
if (results.versions.isEmpty)
@@ -372,7 +382,13 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
372382
WhiskAction.del(entityStore, entity.docinfo).map(_ => entity)
373383
}
374384
}
375-
onComplete(Future.sequence(fs)) {
385+
val deleteFuture = Future.sequence(fs).andThen {
386+
case _ =>
387+
WhiskActionVersionList
388+
.deleteCache(entityName) // invalidate version list cache after all deletion completed
389+
}
390+
391+
onComplete(deleteFuture) {
376392
case Success(entities) =>
377393
complete(OK, entities.last)
378394
case Failure(t: NoDocumentException) =>

core/controller/src/main/scala/org/apache/openwhisk/core/controller/Packages.scala

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,25 @@ trait WhiskPackagesApi extends WhiskCollectionAPI with ReferencedEntities {
8585
}
8686
val referencedentities = referencedEntities(request)
8787

88+
// To avoid using same entity name with action
89+
val latestDocId = WhiskActionVersionList.get(entityName, entityStore).map { result =>
90+
result.matchedDocId(None).getOrElse(entityName.toDocId)
91+
}
92+
8893
onComplete(entitlementProvider.check(user, Privilege.READ, referencedentities)) {
8994
case Success(_) =>
90-
putEntity(
91-
WhiskPackage,
92-
entityStore,
93-
entityName.toDocId,
94-
overwrite,
95-
update(request) _,
96-
() => create(request, entityName))
95+
onComplete(latestDocId) {
96+
case Success(docId) =>
97+
putEntity(
98+
WhiskPackage,
99+
entityStore,
100+
docId,
101+
overwrite,
102+
update(request) _,
103+
() => create(request, entityName))
104+
case Failure(f) =>
105+
terminate(InternalServerError)
106+
}
97107
case Failure(f) =>
98108
rewriteEntitlementFailure(f)
99109
}
@@ -149,14 +159,15 @@ trait WhiskPackagesApi extends WhiskCollectionAPI with ReferencedEntities {
149159
case Right(list) if list.nonEmpty && force =>
150160
Future sequence {
151161
list.map(action => {
152-
WhiskAction.get(
153-
entityStore,
154-
wp.fullyQualifiedName(false)
155-
.add(action.fullyQualifiedName(false).name)
156-
.toDocId) flatMap { actionWithRevision =>
162+
WhiskAction.get(entityStore, action.docid) flatMap { actionWithRevision =>
157163
WhiskAction.del(entityStore, actionWithRevision.docinfo)
158164
}
159165
})
166+
} andThen {
167+
case _ =>
168+
list.foreach { action =>
169+
WhiskActionVersionList.deleteCache(action.fullyQualifiedName(false))
170+
}
160171
} flatMap { _ =>
161172
Future.successful({})
162173
}

core/controller/src/main/scala/org/apache/openwhisk/core/entitlement/PackageCollection.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ class PackageCollection(entityStore: EntityStore)(implicit logging: Logging) ext
6262
case Privilege.READ =>
6363
// must determine if this is a public or owned package
6464
// or, for a binding, that it references a public or owned package
65-
val docid = FullyQualifiedEntityName(resource.namespace.root.toPath, EntityName(pkgname)).toDocId
66-
checkPackageReadPermission(namespaces, isOwner, docid)
65+
val entityName = FullyQualifiedEntityName(resource.namespace.root.toPath, EntityName(pkgname))
66+
WhiskActionVersionList.get(entityName, entityStore).flatMap { result =>
67+
val docid = result.matchedDocId(None).getOrElse(entityName.toDocId)
68+
checkPackageReadPermission(namespaces, isOwner, docid)
69+
}
6770
case _ => Future.successful(isOwner && allowedEntityRights.contains(right))
6871
}
6972
} getOrElse {

tests/src/test/scala/org/apache/openwhisk/core/controller/test/EntitlementProviderTests.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,15 +335,15 @@ class EntitlementProviderTests extends ControllerTestCommon with ScalaFutures {
335335
(REJECT, guestUser, Right(false)))
336336

337337
// this forces a doc mismatch error
338-
val trigger = WhiskTrigger(someUser.namespace.name.toPath, MakeName.next())
339-
put(entityStore, trigger)
338+
val action = WhiskAction(someUser.namespace.name.toPath, MakeName.next(), jsDefault(""))
339+
put(entityStore, action)
340340
paths foreach {
341341
case (priv, who, expected) =>
342342
val check = new PackageCollection(entityStore).implicitRights(
343343
who,
344344
Set(who.namespace.name.asString),
345345
priv,
346-
Resource(someUser.namespace.name.toPath, PACKAGES, Some(trigger.name.asString)))
346+
Resource(someUser.namespace.name.toPath, PACKAGES, Some(action.name.asString)))
347347
Await.ready(check, requestTimeout).eitherValue.get shouldBe expected
348348
}
349349
}

tests/src/test/scala/org/apache/openwhisk/core/controller/test/PackagesApiTests.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -862,11 +862,11 @@ class PackagesApiTests extends ControllerTestCommon with WhiskPackagesApi {
862862

863863
it should "reject bind to non-package" in {
864864
implicit val tid = transid()
865-
val trigger = WhiskTrigger(namespace, aname())
866-
val reference = WhiskPackage(namespace, aname(), Some(Binding(trigger.namespace.root, trigger.name)))
865+
val action = WhiskAction(namespace, aname(), jsDefault("??"))
866+
val reference = WhiskPackage(namespace, aname(), Some(Binding(action.namespace.root, action.name)))
867867
val content = WhiskPackagePut(reference.binding)
868868

869-
put(entityStore, trigger)
869+
put(entityStore, action)
870870

871871
Put(s"$collectionPath/${reference.name}", content) ~> Route.seal(routes(creds)) ~> check {
872872
status should be(Conflict)

0 commit comments

Comments
 (0)