Skip to content

Commit 8760666

Browse files
author
Hariharan Ramanathan
committed
Added test case for failure on large input result
1 parent 706cac9 commit 8760666

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/it/scala/de/upb/cs/swt/delphi/webapi/SearchQueryTest.scala

+13-6
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,24 @@
1616

1717
package de.upb.cs.swt.delphi.webapi
1818

19-
import de.upb.cs.swt.delphi.webapi.search.{QueryRequest, SearchQuery}
19+
import de.upb.cs.swt.delphi.webapi.search.{QueryRequest, SearchError, SearchQuery}
2020
import org.scalatest.{FlatSpec, Matchers}
2121

22-
import scala.util.Success
22+
import scala.util.Failure
2323

2424
class SearchQueryTest extends FlatSpec with Matchers {
25-
"Search query" should "check for fields" in {
25+
"Search query" should "fail on large request limit" in {
2626
val configuration = new Configuration()
2727
val q = new SearchQuery(configuration, new FeatureQuery(configuration))
28-
29-
val response = q.search(QueryRequest("[if_icmpeq (opcode:159)]>1"))
30-
response shouldBe a [Success[_]]
28+
val size = 20000
29+
val response = q.search(QueryRequest("[dstore_1 (opcode:72)]<1", Some(size)))
30+
response match {
31+
case Failure(exception) => {
32+
exception shouldBe a[SearchError]
33+
}
34+
case _ => {
35+
fail("Limit exceeded should fail")
36+
}
37+
}
3138
}
3239
}

src/main/scala/de/upb/cs/swt/delphi/webapi/search/SearchQuery.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class SearchQuery(configuration: Configuration, featureExtractor: FeatureQuery)
129129

130130
def search(query: QueryRequest): Try[Array[Artifact]] = {
131131
lazy val size = checkValidSize
132-
val validSize = size.exists(query.limit.getOrElse(defaultFetchSize) < _)
132+
val validSize = size.exists(query.limit.getOrElse(defaultFetchSize) <= _)
133133
if (validSize) {
134134
val parserResult = new Syntax(query.query).QueryRule.run()
135135
parserResult match {

0 commit comments

Comments
 (0)