@@ -16,6 +16,15 @@ def source_with_posts
1616 } )
1717 end
1818
19+ def source_with_concurrency
20+ Source . new ( site_config , nil , nil , {
21+ repository : "pawelpacana/test-source" ,
22+ path : "posts" ,
23+ encoding : "utf-8" ,
24+ concurrency : 2 ,
25+ } )
26+ end
27+
1928 def empty_source
2029 Source . new ( site_config , nil , nil , {
2130 repository : "pawelpacana/test-empty" ,
@@ -79,6 +88,105 @@ def test_items_in_root
7988 end
8089 end
8190
91+ def post_body
92+ {
93+ name : "post.md" ,
94+ path : "posts/post.md" ,
95+ sha : "3c612584217e21ae00d532a86e0e35685131dbba" ,
96+ size : 23 ,
97+ url : "https://api.github.com/repos/pawelpacana/test-source/contents/posts/post.md?ref=master" ,
98+ html_url : "https://github.com/pawelpacana/test-source/blob/master/posts/post.md" ,
99+ git_url : "https://api.github.com/repos/pawelpacana/test-source/git/blobs/3c612584217e21ae00d532a86e0e35685131dbba" ,
100+ download_url : "https://raw.githubusercontent.com/pawelpacana/test-source/master/posts/post.md" ,
101+ type : "file" ,
102+ content : "IyBUaXRsZQoKU29tZSBjb250ZW50Lgo=\n " ,
103+ encoding : "base64" ,
104+ _links : {
105+ self : "https://api.github.com/repos/pawelpacana/test-source/contents/posts/post.md?ref=master" ,
106+ git : "https://api.github.com/repos/pawelpacana/test-source/git/blobs/3c612584217e21ae00d532a86e0e35685131dbba" ,
107+ html : "https://github.com/pawelpacana/test-source/blob/master/posts/post.md"
108+ }
109+ }
110+ end
111+
112+ def x_post_body
113+ {
114+ name : "x-post.md" ,
115+ path : "posts/x-post.md" ,
116+ sha : "34773833eda5caf2352a1ab8c1ba34e246ab9554" ,
117+ size : 150 ,
118+ url : "https://api.github.com/repos/pawelpacana/test-source/contents/posts/x-post.md?ref=master" ,
119+ html_url : "https://github.com/pawelpacana/test-source/blob/master/posts/x-post.md" ,
120+ git_url : "https://api.github.com/repos/pawelpacana/test-source/git/blobs/34773833eda5caf2352a1ab8c1ba34e246ab9554" ,
121+ download_url : "https://raw.githubusercontent.com/pawelpacana/test-source/master/posts/x-post.md" ,
122+ type : "file" ,
123+ content : "LS0tCnB1Ymxpc2hlZF9hdDogMTk3MC0wMS0wMSAwMTowMDowMCArMDEwMAp0\n YWdzOiBbJ29uZScsICdicmlkZ2UnLCAndG9vJywgJ2ZhciddCmF1dGhvcjog\n SmFuIE1hcmlhCi0tLQoKIyBXaGF0IHdoYXQKClphxbzDs8WCxIcgZ8SZxZts\n xIUgamHFusWEIPCfmYgK\n " ,
124+ encoding : "base64" ,
125+ _links : {
126+ self : "https://api.github.com/repos/pawelpacana/test-source/contents/posts/x-post.md?ref=master" ,
127+ git : "https://api.github.com/repos/pawelpacana/test-source/git/blobs/34773833eda5caf2352a1ab8c1ba34e246ab9554" ,
128+ html : "https://github.com/pawelpacana/test-source/blob/master/posts/x-post.md"
129+ }
130+ }
131+ end
132+
133+ def posts_body
134+ [
135+ {
136+ name : "post.md" ,
137+ path : "posts/post.md" ,
138+ sha : "3c612584217e21ae00d532a86e0e35685131dbba" ,
139+ size : 23 ,
140+ url : "https://api.github.com/repos/pawelpacana/test-source/contents/posts/post.md?ref=master" ,
141+ html_url : "https://github.com/pawelpacana/test-source/blob/master/posts/post.md" ,
142+ git_url : "https://api.github.com/repos/pawelpacana/test-source/git/blobs/3c612584217e21ae00d532a86e0e35685131dbba" ,
143+ download_url : "https://raw.githubusercontent.com/pawelpacana/test-source/master/posts/post.md" ,
144+ type : "file" ,
145+ _links : {
146+ self : "https://api.github.com/repos/pawelpacana/test-source/contents/posts/post.md?ref=master" ,
147+ git : "https://api.github.com/repos/pawelpacana/test-source/git/blobs/3c612584217e21ae00d532a86e0e35685131dbba" ,
148+ html : "https://github.com/pawelpacana/test-source/blob/master/posts/post.md"
149+ }
150+ } ,
151+ {
152+ name : "x-post.md" ,
153+ path : "posts/x-post.md" ,
154+ sha : "34773833eda5caf2352a1ab8c1ba34e246ab9554" ,
155+ size : 150 ,
156+ url : "https://api.github.com/repos/pawelpacana/test-source/contents/posts/x-post.md?ref=master" ,
157+ html_url : "https://github.com/pawelpacana/test-source/blob/master/posts/x-post.md" ,
158+ git_url : "https://api.github.com/repos/pawelpacana/test-source/git/blobs/34773833eda5caf2352a1ab8c1ba34e246ab9554" ,
159+ download_url : "https://raw.githubusercontent.com/pawelpacana/test-source/master/posts/x-post.md" ,
160+ type : "file" ,
161+ _links : {
162+ self : "https://api.github.com/repos/pawelpacana/test-source/contents/posts/x-post.md?ref=master" ,
163+ git : "https://api.github.com/repos/pawelpacana/test-source/git/blobs/34773833eda5caf2352a1ab8c1ba34e246ab9554" ,
164+ html : "https://github.com/pawelpacana/test-source/blob/master/posts/x-post.md"
165+ }
166+ }
167+ ]
168+ end
169+
170+ def json_response ( body )
171+ { status : 200 , body : JSON . dump ( body ) , headers : { CONTENT_TYPE : 'application/json' } }
172+ end
173+
174+ def test_items_out_of_order
175+ VCR . turn_off!
176+ stub_request ( :get , "https://api.github.com/repos/pawelpacana/test-source/contents/posts" )
177+ . to_return { json_response ( posts_body ) }
178+ stub_request ( :get , "https://api.github.com/repos/pawelpacana/test-source/contents/posts/x-post.md" )
179+ . to_return { json_response ( x_post_body ) }
180+ stub_request ( :get , "https://api.github.com/repos/pawelpacana/test-source/contents/posts/post.md" )
181+ . to_return { sleep ( 0.1 ) ; json_response ( post_body ) }
182+
183+
184+ items = source_with_concurrency . items
185+ assert_equal items , items . sort_by { |item | item . identifier }
186+ ensure
187+ VCR . turn_on!
188+ end
189+
82190 def test_item
83191 VCR . use_cassette ( "test_item" ) do
84192 item = source_with_posts . items [ 0 ]
0 commit comments