[ARVADOS] created: bf63e93a4aa7421c06f4172930484b9dfed3058d
git at public.curoverse.com
git at public.curoverse.com
Thu Nov 6 23:48:45 EST 2014
at bf63e93a4aa7421c06f4172930484b9dfed3058d (commit)
commit bf63e93a4aa7421c06f4172930484b9dfed3058d
Author: Tom Clegg <tom at curoverse.com>
Date: Thu Nov 6 22:52:44 2014 -0500
3400: test limit between server maxpagesize and 2x server maxpagesize.
diff --git a/apps/workbench/test/unit/arvados_resource_list_test.rb b/apps/workbench/test/unit/arvados_resource_list_test.rb
index dac6a74..7e88ea5 100644
--- a/apps/workbench/test/unit/arvados_resource_list_test.rb
+++ b/apps/workbench/test/unit/arvados_resource_list_test.rb
@@ -64,6 +64,37 @@ class ResourceListTest < ActiveSupport::TestCase
assert_equal 51, a
end
+ test 'get limited items, limit % page_size != 0' do
+ use_token :admin
+ max_page_size = Collection.
+ where(owner_uuid: 'zzzzz-j7d0g-0201collections').
+ limit(1000000000).
+ fetch_multiple_pages(false).
+ count
+ # Conditions necessary for this test to be valid:
+ assert_operator 200, :>, max_page_size
+ assert_operator 1, :<, max_page_size
+ # Verify that the server really sends max_page_size when asked for max_page_size+1
+ assert_equal max_page_size, Collection.
+ where(owner_uuid: 'zzzzz-j7d0g-0201collections').
+ limit(max_page_size+1).
+ fetch_multiple_pages(false).
+ results.
+ count
+ # Now that we know the max_page_size+1 is in the middle of page 2,
+ # make sure #each returns page 1 and only the requested part of
+ # page 2.
+ a = 0
+ saw_uuid = {}
+ Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').limit(max_page_size+1).each do |item|
+ a += 1
+ saw_uuid[item.uuid] = true
+ end
+ assert_equal max_page_size+1, a
+ # Ensure no overlap between pages
+ assert_equal max_page_size+1, saw_uuid.size
+ end
+
test 'get single page of items' do
use_token :admin
a = 0
diff --git a/services/api/lib/load_param.rb b/services/api/lib/load_param.rb
index 8d5a9d2..6c80cee 100644
--- a/services/api/lib/load_param.rb
+++ b/services/api/lib/load_param.rb
@@ -6,9 +6,12 @@
# @where, @filters, @limit, @offset, @orders
module LoadParam
- # Default limit on number of rows to return in a single query.
+ # Default number of rows to return in a single query.
DEFAULT_LIMIT = 100
+ # Maximum number of rows to return in a single query, even if the client asks for more.
+ MAX_LIMIT = 100
+
# Load params[:where] into @where
def load_where_param
if params[:where].nil? or params[:where] == ""
@@ -55,7 +58,7 @@ module LoadParam
unless params[:limit].to_s.match(/^\d+$/)
raise ArgumentError.new("Invalid value for limit parameter")
end
- @limit = params[:limit].to_i
+ @limit = [params[:limit].to_i, MAX_LIMIT].min
else
@limit = DEFAULT_LIMIT
end
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list