Skip to content
Snippets Groups Projects
Commit b1708560 authored by Rodric Rabbah's avatar Rodric Rabbah Committed by Mark Deuser
Browse files

Split CLI tests into basic usage and integration tests.

Change units from Int to ByteSize for byte-sized-limited, update comments and json serdes, add byte size subtraction, update tests.

Make some const values core package visible.

Make memory option byte-sizes.

Add toString on byte-size and update error messages.

Remove printlns.

Update and move tests around between packages.

Make TimeLimit constructor accept only a duration.

Revert change to log/memory limit constructor so that the type is int not bytesize (really would want to constrain this to be MB but the type conversions aren't that rich and arguably not worth it as this can be hidden behind the private constructor).

Change Bytes to B in toString to avoid 1 bytes vs 1 byte. Should it be byte[s] and append the s only when necessary?

Emit parameters should test fail.

Use python CLI for http test as go cli assumes https.

Add some more tests for limits.

Use Python CLI for two tests that do not work with Go CLI.

Add retry on list operations which might need some time to be consistent.
parent 1a657a08
No related branches found
No related tags found
No related merge requests found
......@@ -225,7 +225,7 @@ class WskAction(override val usePythonCLI: Boolean = false)
parameters: Map[String, JsValue] = Map(),
annotations: Map[String, JsValue] = Map(),
timeout: Option[Duration] = None,
memory: Option[Int] = None,
memory: Option[ByteSize] = None,
logsize: Option[ByteSize] = None,
shared: Option[Boolean] = None,
update: Boolean = false,
......@@ -242,7 +242,7 @@ class WskAction(override val usePythonCLI: Boolean = false)
{ parameters flatMap { p => Seq("-p", p._1, p._2.compactPrint) } } ++
{ annotations flatMap { p => Seq("-a", p._1, p._2.compactPrint) } } ++
{ timeout map { t => Seq("-t", t.toMillis.toString) } getOrElse Seq() } ++
{ memory map { m => Seq("-m", m.toString) } getOrElse Seq() } ++
{ memory map { m => Seq("-m", m.toMB.toString) } getOrElse Seq() } ++
{ logsize map { l => Seq("-l", l.toMB.toString) } getOrElse Seq() } ++
{ shared map { s => Seq("--shared", if (s) "yes" else "no") } getOrElse Seq() }
cli(wp.overrides ++ params, expectedExitCode)
......@@ -373,7 +373,7 @@ class WskRule(override val usePythonCLI: Boolean = false)
name: String,
expectedExitCode: Int = SUCCESS_EXIT)(
implicit wp: WskProps): RunResult = {
val disable = Try { disableRule(name, 30 seconds) }
val disable = Try { disableRule(name, 30 seconds, expectedExitCode) }
if (expectedExitCode != DONTCARE_EXIT)
disable.get // throws exception
super.delete(name, expectedExitCode)
......
......@@ -68,10 +68,8 @@ trait WskTestHelpers extends Matchers {
val deletedAll = assetsToDeleteAfterTest.reverse map {
case ((cli, n, delete)) => n -> Try {
if (delete) {
println(s"deleting $n")
cli.delete(n)(wskprops)
} else {
println(s"sanitizing $n")
cli.sanitize(n)(wskprops)
}
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -17,6 +17,7 @@
package whisk.core.controller.test
import scala.language.postfixOps
import scala.concurrent.duration.DurationInt
import java.io.ByteArrayOutputStream
import java.io.PrintStream
......@@ -591,7 +592,7 @@ class ActionsApiTests extends ControllerTestCommon with WhiskActionsApi {
it should "invoke an action, blocking with timeout" in {
implicit val tid = transid()
val action = WhiskAction(namespace, aname, Exec.js("??"), limits = ActionLimits(TimeLimit(1000), MemoryLimit(), LogLimit()))
val action = WhiskAction(namespace, aname, Exec.js("??"), limits = ActionLimits(TimeLimit(1 second), MemoryLimit(), LogLimit()))
put(entityStore, action)
Post(s"$collectionPath/${action.name}?blocking=true") ~> sealRoute(routes(creds)) ~> check {
status should be(Accepted)
......
......@@ -16,7 +16,9 @@
package whisk.core.entity.test
import scala.BigInt
import scala.Vector
import scala.concurrent.duration.DurationInt
import scala.language.postfixOps
import scala.language.reflectiveCalls
import scala.util.Try
......@@ -24,6 +26,7 @@ import scala.util.Try
import org.junit.runner.RunWith
import org.scalatest.BeforeAndAfter
import org.scalatest.FlatSpec
import org.scalatest.Matchers
import org.scalatest.junit.JUnitRunner
import spray.json.DefaultJsonProtocol._
......@@ -36,6 +39,7 @@ import spray.json.JsString
import spray.json.JsValue
import spray.json.pimpAny
import spray.json.pimpString
import whisk.core.entity.ActionLimits
import whisk.core.entity.ActivationId
import whisk.core.entity.AuthKey
......@@ -43,15 +47,15 @@ import whisk.core.entity.DocId
import whisk.core.entity.DocInfo
import whisk.core.entity.EntityName
import whisk.core.entity.Exec
import whisk.core.entity.LogLimit
import whisk.core.entity.MemoryLimit
import whisk.core.entity.Namespace
import whisk.core.entity.Parameters
import whisk.core.entity.Secret
import whisk.core.entity.SemVer
import whisk.core.entity.TimeLimit
import whisk.core.entity.LogLimit
import whisk.core.entity.UUID
import org.scalatest.Matchers
import whisk.core.entity.size.SizeInt
@RunWith(classOf[JUnitRunner])
class SchemaTests extends FlatSpec with BeforeAndAfter with Matchers {
......@@ -317,9 +321,9 @@ class SchemaTests extends FlatSpec with BeforeAndAfter with Matchers {
it should "properly deserialize JSON" in {
val json = Seq[JsValue](
JsObject("timeout" -> TimeLimit.STD_DURATION.toMillis.toInt.toJson, "memory" -> MemoryLimit.STD_MEMORY.toJson, "logs" -> LogLimit.STD_LOGSIZE.toJson),
JsObject("timeout" -> TimeLimit.STD_DURATION.toMillis.toInt.toJson, "memory" -> MemoryLimit.STD_MEMORY.toJson, "logs" -> LogLimit.STD_LOGSIZE.toJson, "foo" -> "bar".toJson),
JsObject("timeout" -> TimeLimit.STD_DURATION.toMillis.toInt.toJson, "memory" -> MemoryLimit.STD_MEMORY.toJson))
JsObject("timeout" -> TimeLimit.STD_DURATION.toMillis.toInt.toJson, "memory" -> MemoryLimit.STD_MEMORY.toMB.toInt.toJson, "logs" -> LogLimit.STD_LOGSIZE.toMB.toInt.toJson),
JsObject("timeout" -> TimeLimit.STD_DURATION.toMillis.toInt.toJson, "memory" -> MemoryLimit.STD_MEMORY.toMB.toInt.toJson, "logs" -> LogLimit.STD_LOGSIZE.toMB.toInt.toJson, "foo" -> "bar".toJson),
JsObject("timeout" -> TimeLimit.STD_DURATION.toMillis.toInt.toJson, "memory" -> MemoryLimit.STD_MEMORY.toMB.toInt.toJson))
val limits = json.map(ActionLimits.serdes.read)
assert(limits(0) == ActionLimits())
assert(limits(1) == ActionLimits())
......@@ -335,13 +339,13 @@ class SchemaTests extends FlatSpec with BeforeAndAfter with Matchers {
JsObject(),
JsNull,
JsObject("timeout" -> TimeLimit.STD_DURATION.toMillis.toInt.toJson),
JsObject("memory" -> MemoryLimit.STD_MEMORY.toJson),
JsObject("logs" -> (LogLimit.STD_LOGSIZE + 1).toJson),
JsObject("TIMEOUT" -> TimeLimit.STD_DURATION.toMillis.toInt.toJson, "MEMORY" -> MemoryLimit.STD_MEMORY.toJson),
JsObject("timeout" -> (TimeLimit.STD_DURATION.toMillis.toDouble + .01).toJson, "memory" -> (MemoryLimit.STD_MEMORY.toDouble + .01).toJson),
JsObject("memory" -> MemoryLimit.STD_MEMORY.toMB.toInt.toJson),
JsObject("logs" -> (LogLimit.STD_LOGSIZE.toMB.toInt + 1).toJson),
JsObject("TIMEOUT" -> TimeLimit.STD_DURATION.toMillis.toInt.toJson, "MEMORY" -> MemoryLimit.STD_MEMORY.toMB.toInt.toJson),
JsObject("timeout" -> (TimeLimit.STD_DURATION.toMillis.toDouble + .01).toJson, "memory" -> (MemoryLimit.STD_MEMORY.toMB.toDouble + .01).toJson),
JsObject("timeout" -> null, "memory" -> null),
JsObject("timeout" -> JsNull, "memory" -> JsNull),
JsObject("timeout" -> TimeLimit.STD_DURATION.toMillis.toString.toJson, "memory" -> MemoryLimit.STD_MEMORY.toString.toJson))
JsObject("timeout" -> TimeLimit.STD_DURATION.toMillis.toString.toJson, "memory" -> MemoryLimit.STD_MEMORY.toMB.toInt.toString.toJson))
limits.foreach { p =>
val thrown = intercept[DeserializationException] {
......@@ -351,26 +355,35 @@ class SchemaTests extends FlatSpec with BeforeAndAfter with Matchers {
}
it should "pass the correct error message through" in {
val floatNumber = JsNumber(2.5)
val logException = the[DeserializationException] thrownBy LogLimit.serdes.read(floatNumber)
logException.getMessage should include("log limit must be whole number")
val timeException = the[DeserializationException] thrownBy TimeLimit.serdes.read(floatNumber)
timeException.getMessage should include("time limit must be whole number")
val memoryException = the[DeserializationException] thrownBy MemoryLimit.serdes.read(floatNumber)
memoryException.getMessage should include("memory limit must be whole number")
val serdes = Seq(TimeLimit.serdes, MemoryLimit.serdes, LogLimit.serdes)
serdes foreach { s =>
withClue(s"serializer $s") {
if (s != LogLimit.serdes) {
val lb = the[DeserializationException] thrownBy s.read(JsNumber(0))
lb.getMessage should include("below allowed threshold")
} else {
val lb = the[DeserializationException] thrownBy s.read(JsNumber(-1))
lb.getMessage should include("a negative size of an object is not allowed")
}
val ub = the[DeserializationException] thrownBy s.read(JsNumber(Int.MaxValue))
ub.getMessage should include("exceeds allowed threshold")
val int = the[DeserializationException] thrownBy s.read(JsNumber(2.5))
int.getMessage should include("limit must be whole number")
}
}
}
it should "reject bad limit values" in {
an[IllegalArgumentException] should be thrownBy ActionLimits(TimeLimit(TimeLimit.MIN_DURATION.toMillis.toInt - 1), MemoryLimit(), LogLimit())
an[IllegalArgumentException] should be thrownBy ActionLimits(TimeLimit(), MemoryLimit(MemoryLimit.MIN_MEMORY - 1), LogLimit())
an[IllegalArgumentException] should be thrownBy ActionLimits(TimeLimit(), MemoryLimit(), LogLimit(LogLimit.MIN_LOGSIZE - 1))
an[IllegalArgumentException] should be thrownBy ActionLimits(TimeLimit(TimeLimit.MIN_DURATION - 1.millisecond), MemoryLimit(), LogLimit())
an[IllegalArgumentException] should be thrownBy ActionLimits(TimeLimit(), MemoryLimit(MemoryLimit.MIN_MEMORY - 1.B), LogLimit())
an[IllegalArgumentException] should be thrownBy ActionLimits(TimeLimit(), MemoryLimit(), LogLimit(LogLimit.MIN_LOGSIZE - 1.B))
an[IllegalArgumentException] should be thrownBy ActionLimits(TimeLimit(TimeLimit.MAX_DURATION.toMillis.toInt + 1), MemoryLimit(), LogLimit())
an[IllegalArgumentException] should be thrownBy ActionLimits(TimeLimit(), MemoryLimit(MemoryLimit.MAX_MEMORY + 1), LogLimit())
an[IllegalArgumentException] should be thrownBy ActionLimits(TimeLimit(), MemoryLimit(), LogLimit(LogLimit.MAX_LOGSIZE + 1))
an[IllegalArgumentException] should be thrownBy ActionLimits(TimeLimit(TimeLimit.MAX_DURATION + 1.millisecond), MemoryLimit(), LogLimit())
an[IllegalArgumentException] should be thrownBy ActionLimits(TimeLimit(), MemoryLimit(MemoryLimit.MAX_MEMORY + 1.B), LogLimit())
an[IllegalArgumentException] should be thrownBy ActionLimits(TimeLimit(), MemoryLimit(), LogLimit(LogLimit.MAX_LOGSIZE + 1.B))
}
it should "parse activation id as uuid" in {
......
......@@ -31,7 +31,7 @@ class SizeTests extends FlatSpec with Matchers {
behavior of "Size Entity"
// Comparing
it should "1 Byte smaller than 1 kB smaller than 1 mB" in {
it should "1 Byte smaller than 1 KB smaller than 1 MB" in {
val oneByte = 1 B
val oneKB = 1 KB
val oneMB = 1 MB
......@@ -40,7 +40,7 @@ class SizeTests extends FlatSpec with Matchers {
oneKB < oneMB should be(true)
}
it should "3 Bytes smaller than 2 kB smaller than 1 mB" in {
it should "3 Bytes smaller than 2 KB smaller than 1 MB" in {
val myBytes = 3 B
val myKBs = 2 KB
val myMBs = 1 MB
......@@ -49,7 +49,7 @@ class SizeTests extends FlatSpec with Matchers {
myKBs < myMBs should be(true)
}
it should "1 mB greaten than 1 kB greater than 1 Byte" in {
it should "1 MB greater than 1 KB greater than 1 Byte" in {
val oneByte = 1 B
val oneKB = 1 KB
val oneMB = 1 MB
......@@ -58,7 +58,7 @@ class SizeTests extends FlatSpec with Matchers {
oneKB > oneByte should be(true)
}
it should "1 mB == 1024 kB == 1048576 B" in {
it should "1 MB == 1024 KB == 1048576 B" in {
val myBytes = 1048576 B
val myKBs = 1024 KB
val myMBs = 1 MB
......@@ -68,12 +68,27 @@ class SizeTests extends FlatSpec with Matchers {
}
// Addition
it should "1 Byte + 1 kB = 1025 Bytes" in {
(1 B) + (1 KB) should be(1025 B)
it should "1 Byte + 1 KB = 1025 Bytes" in {
1.B + 1.KB should be(1025 B)
}
it should "1 mB + 1 mB = 2 mB" in {
((1 MB) + (1 MB)).toBytes should be((2 MB).toBytes)
it should "1 MB + 1 MB = 2 MB" in {
(1.MB + 1.MB).toBytes should be(2.MB.toBytes)
}
// Subtraction
it should "1 KB - 1B = 1023 Bytes" in {
1.KB - 1.B should be(1023 B)
}
it should "1 MB - 1 MB = 0 MB" in {
1.MB - 1.MB should be(0 B)
}
it should "throw an exception if subtraction leads to a negative size" in {
an[IllegalArgumentException] should be thrownBy {
0.B - 1.B
}
}
// Conversions
......@@ -85,19 +100,19 @@ class SizeTests extends FlatSpec with Matchers {
(1048576 B).toMB should be(1)
}
it should "1 kB to B = 1024" in {
it should "1 KB to B = 1024" in {
(1 KB).toBytes should be(1024)
}
it should "1024 kB to mB = 1" in {
it should "1024 KB to MB = 1" in {
(1024 KB).toMB should be(1)
}
it should "1 mB to B = 1048576" in {
it should "1 MB to B = 1048576" in {
(1 MB).toBytes should be(1048576)
}
it should "1 mB to kB = 1024" in {
it should "1 MB to KB = 1024" in {
(1 MB).toKB should be(1024)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment