passenger 5.0.4 → 5.0.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of passenger might be problematic. Click here for more details.

Files changed (550) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.asc +7 -7
  3. data.tar.gz.asc +7 -7
  4. data/.editorconfig +10 -0
  5. data/CHANGELOG +21 -0
  6. data/build/agents.rb +2 -2
  7. data/build/apache2.rb +6 -5
  8. data/build/common_library.rb +22 -7
  9. data/build/cxx_tests.rb +0 -3
  10. data/build/misc.rb +1 -1
  11. data/dev/parse_file_descriptor_log +119 -0
  12. data/doc/CloudLicensingConfiguration.html +387 -0
  13. data/doc/Design and Architecture.html +2430 -0
  14. data/doc/Packaging.html +488 -0
  15. data/doc/Security of user switching support.html +1833 -0
  16. data/doc/ServerOptimizationGuide.html +659 -0
  17. data/doc/ServerOptimizationGuide.txt.md +8 -0
  18. data/doc/Users guide Apache.html +9116 -0
  19. data/doc/Users guide Apache.idmap.txt +6 -2
  20. data/doc/Users guide Apache.txt +26 -7
  21. data/doc/Users guide Nginx.html +9025 -0
  22. data/doc/Users guide Nginx.idmap.txt +7 -3
  23. data/doc/Users guide Nginx.txt +29 -6
  24. data/doc/Users guide Standalone.html +3983 -0
  25. data/doc/Users guide.html +1748 -0
  26. data/doc/users_guide_snippets/installation.txt +4 -4
  27. data/ext/apache2/Configuration.cpp +16 -5
  28. data/ext/apache2/Configuration.hpp +4 -2
  29. data/ext/apache2/Hooks.cpp +44 -19
  30. data/ext/boost/libs/thread/src/pthread/once.cpp +2 -0
  31. data/ext/boost/libs/thread/src/pthread/once_atomic.cpp +6 -0
  32. data/ext/common/AgentsStarter.h +3 -2
  33. data/ext/common/ApplicationPool2/DirectSpawner.h +14 -4
  34. data/ext/common/ApplicationPool2/DummySpawner.h +12 -7
  35. data/ext/common/ApplicationPool2/Implementation.cpp +1 -1
  36. data/ext/common/ApplicationPool2/Process.h +2 -1
  37. data/ext/common/ApplicationPool2/Session.h +6 -6
  38. data/ext/common/ApplicationPool2/SmartSpawner.h +19 -4
  39. data/ext/common/ApplicationPool2/Socket.h +59 -27
  40. data/ext/common/ApplicationPool2/Spawner.h +2 -2
  41. data/ext/common/BackgroundEventLoop.cpp +6 -1
  42. data/ext/common/Constants.h +1 -1
  43. data/ext/common/EventedClient.h +1 -1
  44. data/ext/common/EventedServer.h +2 -2
  45. data/ext/common/FileDescriptor.h +25 -6
  46. data/ext/common/Logging.cpp +107 -52
  47. data/ext/common/Logging.h +146 -19
  48. data/ext/common/MessageClient.h +2 -2
  49. data/ext/common/MessageServer.h +3 -2
  50. data/ext/common/RandomGenerator.h +8 -7
  51. data/ext/common/SafeLibev.h +5 -1
  52. data/ext/common/ServerKit/AcceptLoadBalancer.h +9 -4
  53. data/ext/common/ServerKit/FdSinkChannel.h +5 -2
  54. data/ext/common/ServerKit/FdSourceChannel.h +5 -2
  55. data/ext/common/ServerKit/FileBufferedChannel.h +2 -0
  56. data/ext/common/ServerKit/FileBufferedFdSinkChannel.h +7 -2
  57. data/ext/common/ServerKit/HttpServer.h +6 -0
  58. data/ext/common/ServerKit/Server.h +40 -3
  59. data/ext/common/StaticString.h +20 -0
  60. data/ext/common/UnionStation/Connection.h +3 -1
  61. data/ext/common/UnionStation/Core.h +6 -4
  62. data/ext/common/Utils.cpp +4 -3
  63. data/ext/common/Utils/DateParsing.h +19 -5
  64. data/ext/common/Utils/FastStringStream.h +183 -0
  65. data/ext/common/Utils/IOUtils.cpp +47 -28
  66. data/ext/common/Utils/IOUtils.h +56 -12
  67. data/ext/common/Utils/MessagePassing.h +3 -3
  68. data/ext/common/Utils/ProcessMetricsCollector.h +2 -2
  69. data/ext/common/Utils/ScopeGuard.h +16 -5
  70. data/ext/common/Utils/SpeedMeter.h +2 -2
  71. data/ext/common/Utils/StrIntUtils.cpp +6 -6
  72. data/ext/common/Utils/StrIntUtils.h +2 -1
  73. data/ext/common/agents/Base.cpp +56 -4
  74. data/ext/common/agents/Base.h +2 -1
  75. data/ext/common/agents/HelperAgent/AdminServer.h +122 -11
  76. data/ext/common/agents/HelperAgent/Main.cpp +16 -5
  77. data/ext/common/agents/HelperAgent/OptionParser.h +7 -1
  78. data/ext/common/agents/HelperAgent/RequestHandler.h +1 -1
  79. data/ext/common/agents/HelperAgent/RequestHandler/Hooks.cpp +10 -1
  80. data/ext/common/agents/HelperAgent/RequestHandler/Request.h +8 -0
  81. data/ext/common/agents/HelperAgent/RequestHandler/TurboCaching.h +4 -3
  82. data/ext/common/agents/LoggingAgent/AdminServer.h +57 -11
  83. data/ext/common/agents/LoggingAgent/LoggingServer.h +3 -3
  84. data/ext/common/agents/LoggingAgent/Main.cpp +11 -3
  85. data/ext/common/agents/Watchdog/AdminServer.h +53 -11
  86. data/ext/common/agents/Watchdog/AgentWatcher.cpp +3 -3
  87. data/ext/common/agents/Watchdog/Main.cpp +13 -6
  88. data/ext/libeio/ecb.h +1 -1
  89. data/ext/libev/ev.c +13 -1
  90. data/ext/libev/ev.h +3 -0
  91. data/ext/nginx/Configuration.c +28 -6
  92. data/ext/nginx/Configuration.h +2 -1
  93. data/ext/nginx/ngx_http_passenger_module.c +5 -4
  94. data/ext/oxt/dynamic_thread_group.hpp +38 -5
  95. data/lib/phusion_passenger.rb +1 -1
  96. data/lib/phusion_passenger/common_library.rb +9 -5
  97. data/lib/phusion_passenger/config/reopen_logs_command.rb +2 -2
  98. data/lib/phusion_passenger/packaging.rb +23 -37
  99. data/passenger.gemspec +21 -21
  100. metadata +4 -453
  101. metadata.gz.asc +7 -7
  102. data/.gitignore +0 -68
  103. data/.travis.yml +0 -16
  104. data/Gemfile +0 -17
  105. data/Gemfile.lock +0 -39
  106. data/Vagrantfile +0 -54
  107. data/debian.template/README.Debian +0 -15
  108. data/debian.template/changelog +0 -316
  109. data/debian.template/compat +0 -1
  110. data/debian.template/control.erb +0 -91
  111. data/debian.template/copyright +0 -385
  112. data/debian.template/libapache2-mod-passenger.install +0 -3
  113. data/debian.template/libapache2-mod-passenger.postinst +0 -36
  114. data/debian.template/libapache2-mod-passenger.prerm +0 -15
  115. data/debian.template/locations.ini.erb +0 -14
  116. data/debian.template/passenger-dev.install.erb +0 -3
  117. data/debian.template/passenger-doc.install.erb +0 -2
  118. data/debian.template/passenger.conf +0 -6
  119. data/debian.template/passenger.docs +0 -4
  120. data/debian.template/passenger.install.erb +0 -14
  121. data/debian.template/passenger.load +0 -3
  122. data/debian.template/passenger.manpages +0 -3
  123. data/debian.template/patches/series +0 -0
  124. data/debian.template/rules.erb +0 -76
  125. data/debian.template/source/format +0 -1
  126. data/ext/common/EventedBufferedInput.h +0 -458
  127. data/packaging/rpm/LICENSE.txt +0 -19
  128. data/packaging/rpm/Makefile +0 -13
  129. data/packaging/rpm/README.md +0 -41
  130. data/packaging/rpm/Vagrantfile +0 -38
  131. data/packaging/rpm/Vagrantfile.centos +0 -30
  132. data/packaging/rpm/build +0 -170
  133. data/packaging/rpm/create_project +0 -41
  134. data/packaging/rpm/git_update +0 -88
  135. data/packaging/rpm/image/Dockerfile +0 -37
  136. data/packaging/rpm/image/Gemfile +0 -3
  137. data/packaging/rpm/image/Gemfile.lock +0 -12
  138. data/packaging/rpm/image/RPM-GPG-KEY-amazon-ga +0 -19
  139. data/packaging/rpm/image/amazon2014-i386.cfg +0 -96
  140. data/packaging/rpm/image/amazon2014-x86_64.cfg +0 -96
  141. data/packaging/rpm/image/site-defaults.cfg +0 -168
  142. data/packaging/rpm/internal/build_tasks.rb +0 -238
  143. data/packaging/rpm/internal/dummygpg +0 -11
  144. data/packaging/rpm/internal/exec_build +0 -42
  145. data/packaging/rpm/internal/get_distro_arch +0 -14
  146. data/packaging/rpm/internal/get_distro_id +0 -10
  147. data/packaging/rpm/internal/git_update +0 -27
  148. data/packaging/rpm/internal/inituidgid +0 -17
  149. data/packaging/rpm/internal/my_init +0 -344
  150. data/packaging/rpm/internal/python27 +0 -3
  151. data/packaging/rpm/internal/repo_update +0 -46
  152. data/packaging/rpm/internal/setuser +0 -26
  153. data/packaging/rpm/internal/tracking_helper +0 -40
  154. data/packaging/rpm/jenkins_release +0 -99
  155. data/packaging/rpm/lib/build_tasks_support.rb +0 -402
  156. data/packaging/rpm/lib/preprocessor.rb +0 -341
  157. data/packaging/rpm/nginx_spec/404.html +0 -119
  158. data/packaging/rpm/nginx_spec/50x.html +0 -119
  159. data/packaging/rpm/nginx_spec/index.html +0 -116
  160. data/packaging/rpm/nginx_spec/nginx-auto-cc-gcc.patch +0 -13
  161. data/packaging/rpm/nginx_spec/nginx-logo.png +0 -0
  162. data/packaging/rpm/nginx_spec/nginx-upgrade +0 -13
  163. data/packaging/rpm/nginx_spec/nginx-upgrade.8 +0 -151
  164. data/packaging/rpm/nginx_spec/nginx.conf +0 -131
  165. data/packaging/rpm/nginx_spec/nginx.init +0 -144
  166. data/packaging/rpm/nginx_spec/nginx.logrotate +0 -13
  167. data/packaging/rpm/nginx_spec/nginx.service +0 -15
  168. data/packaging/rpm/nginx_spec/nginx.spec.template +0 -560
  169. data/packaging/rpm/nginx_spec/nginx.sysconfig +0 -4
  170. data/packaging/rpm/nginx_spec/passenger.conf +0 -9
  171. data/packaging/rpm/nginx_spec/poweredby.png +0 -0
  172. data/packaging/rpm/passenger_spec/apache-passenger.conf.in +0 -26
  173. data/packaging/rpm/passenger_spec/config.json +0 -30
  174. data/packaging/rpm/passenger_spec/passenger.logrotate +0 -7
  175. data/packaging/rpm/passenger_spec/passenger.spec.template +0 -478
  176. data/packaging/rpm/passenger_spec/passenger_dynamic_thread_group.patch +0 -16
  177. data/packaging/rpm/passenger_spec/passenger_tests_default_config_example.patch +0 -44
  178. data/packaging/rpm/passenger_spec/rubygem-passenger-4.0.18-GLIBC_HAVE_LONG_LONG.patch +0 -21
  179. data/packaging/rpm/repo_update +0 -114
  180. data/packaging/rpm/setup-system +0 -61
  181. data/packaging/rpm/shell +0 -10
  182. data/test/.rspec +0 -4
  183. data/test/config.json.example +0 -42
  184. data/test/config.json.rpm-automation +0 -15
  185. data/test/config.json.travis +0 -15
  186. data/test/config.json.vagrant +0 -30
  187. data/test/cxx/ApplicationPool2/DirectSpawnerTest.cpp +0 -124
  188. data/test/cxx/ApplicationPool2/OptionsTest.cpp +0 -30
  189. data/test/cxx/ApplicationPool2/PoolTest.cpp +0 -2062
  190. data/test/cxx/ApplicationPool2/ProcessTest.cpp +0 -130
  191. data/test/cxx/ApplicationPool2/SmartSpawnerTest.cpp +0 -243
  192. data/test/cxx/ApplicationPool2/SpawnerTestCases.cpp +0 -823
  193. data/test/cxx/BufferedIOTest.cpp +0 -364
  194. data/test/cxx/CachedFileStatTest.cpp +0 -402
  195. data/test/cxx/CxxTestMain.cpp +0 -181
  196. data/test/cxx/DataStructures/LStringTest.cpp +0 -275
  197. data/test/cxx/DataStructures/StringKeyTableTest.cpp +0 -199
  198. data/test/cxx/DateParsingTest.cpp +0 -75
  199. data/test/cxx/DechunkerTest.cpp +0 -250
  200. data/test/cxx/EventedBufferedInputTest.cpp +0 -758
  201. data/test/cxx/EventedClientTest.cpp +0 -523
  202. data/test/cxx/FileChangeCheckerTest.cpp +0 -331
  203. data/test/cxx/FileDescriptorTest.cpp +0 -69
  204. data/test/cxx/FilterSupportTest.cpp +0 -433
  205. data/test/cxx/IOUtilsTest.cpp +0 -861
  206. data/test/cxx/MemoryKit/MbufTest.cpp +0 -213
  207. data/test/cxx/MessageIOTest.cpp +0 -360
  208. data/test/cxx/MessagePassingTest.cpp +0 -81
  209. data/test/cxx/MessageReadersWritersTest.cpp +0 -576
  210. data/test/cxx/MessageServerTest.cpp +0 -393
  211. data/test/cxx/ProcessMetricsCollectorTest.cpp +0 -123
  212. data/test/cxx/RequestHandlerTest.cpp +0 -1463
  213. data/test/cxx/ResponseCacheTest.cpp +0 -322
  214. data/test/cxx/ServerKit/ChannelTest.cpp +0 -1467
  215. data/test/cxx/ServerKit/CookieUtilsTest.cpp +0 -274
  216. data/test/cxx/ServerKit/FileBufferedChannelTest.cpp +0 -992
  217. data/test/cxx/ServerKit/HeaderTableTest.cpp +0 -177
  218. data/test/cxx/ServerKit/HttpServerTest.cpp +0 -1580
  219. data/test/cxx/ServerKit/ServerTest.cpp +0 -408
  220. data/test/cxx/StaticStringTest.cpp +0 -220
  221. data/test/cxx/StringMapTest.cpp +0 -131
  222. data/test/cxx/SystemTimeTest.cpp +0 -37
  223. data/test/cxx/TemplateTest.cpp +0 -118
  224. data/test/cxx/TestSupport.cpp +0 -207
  225. data/test/cxx/TestSupport.h +0 -333
  226. data/test/cxx/UnionStationTest.cpp +0 -741
  227. data/test/cxx/Utils/StrIntUtilsTest.cpp +0 -39
  228. data/test/cxx/UtilsTest.cpp +0 -672
  229. data/test/cxx/VariantMapTest.cpp +0 -191
  230. data/test/gdbinit.example +0 -34
  231. data/test/integration_tests/apache2_tests.rb +0 -585
  232. data/test/integration_tests/downloaded_binaries_tests.rb +0 -185
  233. data/test/integration_tests/native_packaging_spec.rb +0 -368
  234. data/test/integration_tests/nginx_tests.rb +0 -402
  235. data/test/integration_tests/shared/example_webapp_tests.rb +0 -289
  236. data/test/integration_tests/source_packaging_test.rb +0 -201
  237. data/test/integration_tests/spec_helper.rb +0 -22
  238. data/test/integration_tests/standalone_tests.rb +0 -392
  239. data/test/node/line_reader_spec.js +0 -338
  240. data/test/node/spec_helper.js +0 -65
  241. data/test/oxt/backtrace_test.cpp +0 -88
  242. data/test/oxt/counter.hpp +0 -55
  243. data/test/oxt/dynamic_thread_group_test.cpp +0 -131
  244. data/test/oxt/oxt_test_main.cpp +0 -27
  245. data/test/oxt/spin_lock_test.cpp +0 -59
  246. data/test/oxt/syscall_interruption_test.cpp +0 -39
  247. data/test/ruby/debug_logging_spec.rb +0 -145
  248. data/test/ruby/message_channel_spec.rb +0 -196
  249. data/test/ruby/rack/loader_spec.rb +0 -42
  250. data/test/ruby/rack/preloader_spec.rb +0 -48
  251. data/test/ruby/rails3.0/loader_spec.rb +0 -26
  252. data/test/ruby/rails3.0/preloader_spec.rb +0 -32
  253. data/test/ruby/rails3.1/loader_spec.rb +0 -26
  254. data/test/ruby/rails3.1/preloader_spec.rb +0 -32
  255. data/test/ruby/rails3.2/loader_spec.rb +0 -26
  256. data/test/ruby/rails3.2/preloader_spec.rb +0 -32
  257. data/test/ruby/rails4.0/loader_spec.rb +0 -28
  258. data/test/ruby/rails4.0/preloader_spec.rb +0 -34
  259. data/test/ruby/rails4.1/loader_spec.rb +0 -28
  260. data/test/ruby/rails4.1/preloader_spec.rb +0 -34
  261. data/test/ruby/request_handler_spec.rb +0 -747
  262. data/test/ruby/shared/loader_sharedspec.rb +0 -247
  263. data/test/ruby/shared/rails/union_station_extensions_sharedspec.rb +0 -357
  264. data/test/ruby/shared/ruby_loader_sharedspec.rb +0 -55
  265. data/test/ruby/spec_helper.rb +0 -114
  266. data/test/ruby/standalone/runtime_installer_spec.rb +0 -402
  267. data/test/ruby/union_station_spec.rb +0 -288
  268. data/test/ruby/utils/file_system_watcher_spec.rb +0 -229
  269. data/test/ruby/utils/hosts_file_parser.rb +0 -258
  270. data/test/ruby/utils/tee_input_spec.rb +0 -235
  271. data/test/ruby/utils/unseekable_socket_spec.rb +0 -66
  272. data/test/ruby/utils_spec.rb +0 -41
  273. data/test/stub/apache2/httpd.conf.erb +0 -122
  274. data/test/stub/apache2/mime.types +0 -748
  275. data/test/stub/garbage1.dat +0 -0
  276. data/test/stub/garbage2.dat +0 -0
  277. data/test/stub/garbage3.dat +0 -0
  278. data/test/stub/http_request.yml +0 -23
  279. data/test/stub/index.html +0 -1
  280. data/test/stub/nginx/koi-utf +0 -109
  281. data/test/stub/nginx/koi-win +0 -103
  282. data/test/stub/nginx/mime.types +0 -70
  283. data/test/stub/nginx/nginx.conf.erb +0 -70
  284. data/test/stub/nginx/win-utf +0 -126
  285. data/test/stub/node/app.js +0 -133
  286. data/test/stub/node/public/.gitignore +0 -0
  287. data/test/stub/node/tmp/.gitignore +0 -0
  288. data/test/stub/rack/config.ru +0 -95
  289. data/test/stub/rack/library.rb +0 -16
  290. data/test/stub/rack/public/.gitignore +0 -0
  291. data/test/stub/rack/start.rb +0 -52
  292. data/test/stub/rack/tmp/.gitignore +0 -0
  293. data/test/stub/rails3.0/.gitignore +0 -4
  294. data/test/stub/rails3.0/Gemfile +0 -22
  295. data/test/stub/rails3.0/Gemfile.lock +0 -80
  296. data/test/stub/rails3.0/Rakefile +0 -10
  297. data/test/stub/rails3.0/app/controllers/application_controller.rb +0 -4
  298. data/test/stub/rails3.0/app/helpers/application_helper.rb +0 -2
  299. data/test/stub/rails3.0/app/views/layouts/application.html.erb +0 -14
  300. data/test/stub/rails3.0/config.ru +0 -4
  301. data/test/stub/rails3.0/config/application.rb +0 -48
  302. data/test/stub/rails3.0/config/boot.rb +0 -13
  303. data/test/stub/rails3.0/config/database.yml +0 -22
  304. data/test/stub/rails3.0/config/environment.rb +0 -5
  305. data/test/stub/rails3.0/config/environments/development.rb +0 -19
  306. data/test/stub/rails3.0/config/environments/production.rb +0 -48
  307. data/test/stub/rails3.0/config/environments/test.rb +0 -32
  308. data/test/stub/rails3.0/config/initializers/backtrace_silencers.rb +0 -7
  309. data/test/stub/rails3.0/config/initializers/inflections.rb +0 -10
  310. data/test/stub/rails3.0/config/initializers/mime_types.rb +0 -5
  311. data/test/stub/rails3.0/config/initializers/passenger.rb +0 -2
  312. data/test/stub/rails3.0/config/initializers/secret_token.rb +0 -7
  313. data/test/stub/rails3.0/config/initializers/session_store.rb +0 -8
  314. data/test/stub/rails3.0/config/locales/en.yml +0 -5
  315. data/test/stub/rails3.0/config/routes.rb +0 -58
  316. data/test/stub/rails3.0/db/seeds.rb +0 -7
  317. data/test/stub/rails3.0/doc/README_FOR_APP +0 -2
  318. data/test/stub/rails3.0/lib/tasks/.gitkeep +0 -0
  319. data/test/stub/rails3.0/log/.gitignore +0 -0
  320. data/test/stub/rails3.0/public/404.html +0 -26
  321. data/test/stub/rails3.0/public/422.html +0 -26
  322. data/test/stub/rails3.0/public/500.html +0 -26
  323. data/test/stub/rails3.0/public/favicon.ico +0 -0
  324. data/test/stub/rails3.0/public/index.html +0 -279
  325. data/test/stub/rails3.0/public/robots.txt +0 -5
  326. data/test/stub/rails3.0/public/stylesheets/.gitkeep +0 -0
  327. data/test/stub/rails3.0/script/rails +0 -9
  328. data/test/stub/rails3.0/test/performance/browsing_test.rb +0 -9
  329. data/test/stub/rails3.0/test/test_helper.rb +0 -13
  330. data/test/stub/rails3.0/vendor/plugins/.gitkeep +0 -0
  331. data/test/stub/rails3.1/.gitignore +0 -15
  332. data/test/stub/rails3.1/Gemfile +0 -37
  333. data/test/stub/rails3.1/Gemfile.lock +0 -115
  334. data/test/stub/rails3.1/README +0 -261
  335. data/test/stub/rails3.1/Rakefile +0 -7
  336. data/test/stub/rails3.1/app/assets/images/rails.png +0 -0
  337. data/test/stub/rails3.1/app/assets/stylesheets/application.css +0 -7
  338. data/test/stub/rails3.1/app/controllers/application_controller.rb +0 -3
  339. data/test/stub/rails3.1/app/helpers/application_helper.rb +0 -2
  340. data/test/stub/rails3.1/app/mailers/.gitkeep +0 -0
  341. data/test/stub/rails3.1/app/models/.gitkeep +0 -0
  342. data/test/stub/rails3.1/app/views/layouts/application.html.erb +0 -14
  343. data/test/stub/rails3.1/config.ru +0 -4
  344. data/test/stub/rails3.1/config/application.rb +0 -48
  345. data/test/stub/rails3.1/config/boot.rb +0 -6
  346. data/test/stub/rails3.1/config/database.yml +0 -25
  347. data/test/stub/rails3.1/config/environment.rb +0 -5
  348. data/test/stub/rails3.1/config/environments/development.rb +0 -30
  349. data/test/stub/rails3.1/config/environments/production.rb +0 -60
  350. data/test/stub/rails3.1/config/environments/test.rb +0 -39
  351. data/test/stub/rails3.1/config/initializers/backtrace_silencers.rb +0 -7
  352. data/test/stub/rails3.1/config/initializers/inflections.rb +0 -10
  353. data/test/stub/rails3.1/config/initializers/mime_types.rb +0 -5
  354. data/test/stub/rails3.1/config/initializers/passenger.rb +0 -2
  355. data/test/stub/rails3.1/config/initializers/secret_token.rb +0 -7
  356. data/test/stub/rails3.1/config/initializers/session_store.rb +0 -8
  357. data/test/stub/rails3.1/config/initializers/wrap_parameters.rb +0 -14
  358. data/test/stub/rails3.1/config/locales/en.yml +0 -5
  359. data/test/stub/rails3.1/config/routes.rb +0 -58
  360. data/test/stub/rails3.1/db/seeds.rb +0 -7
  361. data/test/stub/rails3.1/doc/README_FOR_APP +0 -2
  362. data/test/stub/rails3.1/lib/assets/.gitkeep +0 -0
  363. data/test/stub/rails3.1/lib/tasks/.gitkeep +0 -0
  364. data/test/stub/rails3.1/log/.gitkeep +0 -0
  365. data/test/stub/rails3.1/public/404.html +0 -26
  366. data/test/stub/rails3.1/public/422.html +0 -26
  367. data/test/stub/rails3.1/public/500.html +0 -26
  368. data/test/stub/rails3.1/public/favicon.ico +0 -0
  369. data/test/stub/rails3.1/public/index.html +0 -241
  370. data/test/stub/rails3.1/public/robots.txt +0 -5
  371. data/test/stub/rails3.1/script/rails +0 -6
  372. data/test/stub/rails3.1/test/fixtures/.gitkeep +0 -0
  373. data/test/stub/rails3.1/test/functional/.gitkeep +0 -0
  374. data/test/stub/rails3.1/test/integration/.gitkeep +0 -0
  375. data/test/stub/rails3.1/test/performance/browsing_test.rb +0 -12
  376. data/test/stub/rails3.1/test/test_helper.rb +0 -13
  377. data/test/stub/rails3.1/test/unit/.gitkeep +0 -0
  378. data/test/stub/rails3.1/vendor/assets/stylesheets/.gitkeep +0 -0
  379. data/test/stub/rails3.1/vendor/plugins/.gitkeep +0 -0
  380. data/test/stub/rails3.2/.gitignore +0 -15
  381. data/test/stub/rails3.2/Gemfile +0 -39
  382. data/test/stub/rails3.2/Gemfile.lock +0 -113
  383. data/test/stub/rails3.2/Rakefile +0 -7
  384. data/test/stub/rails3.2/app/assets/images/rails.png +0 -0
  385. data/test/stub/rails3.2/app/assets/stylesheets/application.css +0 -13
  386. data/test/stub/rails3.2/app/controllers/application_controller.rb +0 -3
  387. data/test/stub/rails3.2/app/helpers/application_helper.rb +0 -2
  388. data/test/stub/rails3.2/app/mailers/.gitkeep +0 -0
  389. data/test/stub/rails3.2/app/models/.gitkeep +0 -0
  390. data/test/stub/rails3.2/app/views/layouts/application.html.erb +0 -14
  391. data/test/stub/rails3.2/config.ru +0 -4
  392. data/test/stub/rails3.2/config/application.rb +0 -62
  393. data/test/stub/rails3.2/config/boot.rb +0 -6
  394. data/test/stub/rails3.2/config/database.yml +0 -25
  395. data/test/stub/rails3.2/config/environment.rb +0 -5
  396. data/test/stub/rails3.2/config/environments/development.rb +0 -37
  397. data/test/stub/rails3.2/config/environments/production.rb +0 -67
  398. data/test/stub/rails3.2/config/environments/test.rb +0 -37
  399. data/test/stub/rails3.2/config/initializers/backtrace_silencers.rb +0 -7
  400. data/test/stub/rails3.2/config/initializers/inflections.rb +0 -15
  401. data/test/stub/rails3.2/config/initializers/mime_types.rb +0 -5
  402. data/test/stub/rails3.2/config/initializers/passenger.rb +0 -2
  403. data/test/stub/rails3.2/config/initializers/secret_token.rb +0 -7
  404. data/test/stub/rails3.2/config/initializers/session_store.rb +0 -8
  405. data/test/stub/rails3.2/config/initializers/wrap_parameters.rb +0 -14
  406. data/test/stub/rails3.2/config/locales/en.yml +0 -5
  407. data/test/stub/rails3.2/config/routes.rb +0 -58
  408. data/test/stub/rails3.2/db/seeds.rb +0 -7
  409. data/test/stub/rails3.2/doc/README_FOR_APP +0 -2
  410. data/test/stub/rails3.2/lib/assets/.gitkeep +0 -0
  411. data/test/stub/rails3.2/lib/tasks/.gitkeep +0 -0
  412. data/test/stub/rails3.2/log/.gitkeep +0 -0
  413. data/test/stub/rails3.2/public/404.html +0 -26
  414. data/test/stub/rails3.2/public/422.html +0 -26
  415. data/test/stub/rails3.2/public/500.html +0 -25
  416. data/test/stub/rails3.2/public/favicon.ico +0 -0
  417. data/test/stub/rails3.2/public/index.html +0 -241
  418. data/test/stub/rails3.2/public/robots.txt +0 -5
  419. data/test/stub/rails3.2/script/rails +0 -6
  420. data/test/stub/rails3.2/test/fixtures/.gitkeep +0 -0
  421. data/test/stub/rails3.2/test/functional/.gitkeep +0 -0
  422. data/test/stub/rails3.2/test/integration/.gitkeep +0 -0
  423. data/test/stub/rails3.2/test/performance/browsing_test.rb +0 -12
  424. data/test/stub/rails3.2/test/test_helper.rb +0 -13
  425. data/test/stub/rails3.2/test/unit/.gitkeep +0 -0
  426. data/test/stub/rails3.2/vendor/assets/stylesheets/.gitkeep +0 -0
  427. data/test/stub/rails3.2/vendor/plugins/.gitkeep +0 -0
  428. data/test/stub/rails4.0/.gitignore +0 -16
  429. data/test/stub/rails4.0/Gemfile +0 -45
  430. data/test/stub/rails4.0/Gemfile.lock +0 -126
  431. data/test/stub/rails4.0/README.rdoc +0 -28
  432. data/test/stub/rails4.0/Rakefile +0 -6
  433. data/test/stub/rails4.0/app/assets/images/.keep +0 -0
  434. data/test/stub/rails4.0/app/assets/javascripts/application.js +0 -16
  435. data/test/stub/rails4.0/app/assets/stylesheets/application.css +0 -13
  436. data/test/stub/rails4.0/app/controllers/application_controller.rb +0 -5
  437. data/test/stub/rails4.0/app/controllers/concerns/.keep +0 -0
  438. data/test/stub/rails4.0/app/helpers/application_helper.rb +0 -2
  439. data/test/stub/rails4.0/app/mailers/.keep +0 -0
  440. data/test/stub/rails4.0/app/models/.keep +0 -0
  441. data/test/stub/rails4.0/app/models/concerns/.keep +0 -0
  442. data/test/stub/rails4.0/app/views/layouts/application.html.erb +0 -14
  443. data/test/stub/rails4.0/bin/bundle +0 -3
  444. data/test/stub/rails4.0/bin/rails +0 -4
  445. data/test/stub/rails4.0/bin/rake +0 -4
  446. data/test/stub/rails4.0/config.ru +0 -4
  447. data/test/stub/rails4.0/config/application.rb +0 -23
  448. data/test/stub/rails4.0/config/boot.rb +0 -4
  449. data/test/stub/rails4.0/config/database.yml +0 -25
  450. data/test/stub/rails4.0/config/environment.rb +0 -5
  451. data/test/stub/rails4.0/config/environments/development.rb +0 -29
  452. data/test/stub/rails4.0/config/environments/production.rb +0 -80
  453. data/test/stub/rails4.0/config/environments/test.rb +0 -36
  454. data/test/stub/rails4.0/config/initializers/backtrace_silencers.rb +0 -7
  455. data/test/stub/rails4.0/config/initializers/filter_parameter_logging.rb +0 -4
  456. data/test/stub/rails4.0/config/initializers/inflections.rb +0 -16
  457. data/test/stub/rails4.0/config/initializers/mime_types.rb +0 -5
  458. data/test/stub/rails4.0/config/initializers/passenger.rb +0 -2
  459. data/test/stub/rails4.0/config/initializers/secret_token.rb +0 -12
  460. data/test/stub/rails4.0/config/initializers/session_store.rb +0 -3
  461. data/test/stub/rails4.0/config/initializers/wrap_parameters.rb +0 -14
  462. data/test/stub/rails4.0/config/locales/en.yml +0 -23
  463. data/test/stub/rails4.0/config/routes.rb +0 -57
  464. data/test/stub/rails4.0/db/seeds.rb +0 -7
  465. data/test/stub/rails4.0/lib/assets/.keep +0 -0
  466. data/test/stub/rails4.0/lib/tasks/.keep +0 -0
  467. data/test/stub/rails4.0/log/.keep +0 -0
  468. data/test/stub/rails4.0/public/404.html +0 -58
  469. data/test/stub/rails4.0/public/422.html +0 -58
  470. data/test/stub/rails4.0/public/500.html +0 -57
  471. data/test/stub/rails4.0/public/favicon.ico +0 -0
  472. data/test/stub/rails4.0/public/robots.txt +0 -5
  473. data/test/stub/rails4.0/test/controllers/.keep +0 -0
  474. data/test/stub/rails4.0/test/fixtures/.keep +0 -0
  475. data/test/stub/rails4.0/test/helpers/.keep +0 -0
  476. data/test/stub/rails4.0/test/integration/.keep +0 -0
  477. data/test/stub/rails4.0/test/mailers/.keep +0 -0
  478. data/test/stub/rails4.0/test/models/.keep +0 -0
  479. data/test/stub/rails4.0/test/test_helper.rb +0 -15
  480. data/test/stub/rails4.0/vendor/assets/javascripts/.keep +0 -0
  481. data/test/stub/rails4.0/vendor/assets/stylesheets/.keep +0 -0
  482. data/test/stub/rails4.1/.gitignore +0 -16
  483. data/test/stub/rails4.1/Gemfile +0 -45
  484. data/test/stub/rails4.1/Gemfile.lock +0 -129
  485. data/test/stub/rails4.1/README.rdoc +0 -28
  486. data/test/stub/rails4.1/Rakefile +0 -6
  487. data/test/stub/rails4.1/app/assets/images/.keep +0 -0
  488. data/test/stub/rails4.1/app/assets/javascripts/application.js +0 -16
  489. data/test/stub/rails4.1/app/assets/stylesheets/application.css +0 -13
  490. data/test/stub/rails4.1/app/controllers/application_controller.rb +0 -5
  491. data/test/stub/rails4.1/app/controllers/concerns/.keep +0 -0
  492. data/test/stub/rails4.1/app/helpers/application_helper.rb +0 -2
  493. data/test/stub/rails4.1/app/mailers/.keep +0 -0
  494. data/test/stub/rails4.1/app/models/.keep +0 -0
  495. data/test/stub/rails4.1/app/models/concerns/.keep +0 -0
  496. data/test/stub/rails4.1/app/views/layouts/application.html.erb +0 -14
  497. data/test/stub/rails4.1/bin/bundle +0 -3
  498. data/test/stub/rails4.1/bin/rails +0 -4
  499. data/test/stub/rails4.1/bin/rake +0 -4
  500. data/test/stub/rails4.1/config.ru +0 -4
  501. data/test/stub/rails4.1/config/application.rb +0 -23
  502. data/test/stub/rails4.1/config/boot.rb +0 -4
  503. data/test/stub/rails4.1/config/database.yml +0 -25
  504. data/test/stub/rails4.1/config/environment.rb +0 -5
  505. data/test/stub/rails4.1/config/environments/development.rb +0 -29
  506. data/test/stub/rails4.1/config/environments/production.rb +0 -80
  507. data/test/stub/rails4.1/config/environments/test.rb +0 -36
  508. data/test/stub/rails4.1/config/initializers/backtrace_silencers.rb +0 -7
  509. data/test/stub/rails4.1/config/initializers/filter_parameter_logging.rb +0 -4
  510. data/test/stub/rails4.1/config/initializers/inflections.rb +0 -16
  511. data/test/stub/rails4.1/config/initializers/mime_types.rb +0 -5
  512. data/test/stub/rails4.1/config/initializers/passenger.rb +0 -5
  513. data/test/stub/rails4.1/config/initializers/secret_token.rb +0 -12
  514. data/test/stub/rails4.1/config/initializers/session_store.rb +0 -3
  515. data/test/stub/rails4.1/config/initializers/wrap_parameters.rb +0 -14
  516. data/test/stub/rails4.1/config/locales/en.yml +0 -23
  517. data/test/stub/rails4.1/config/routes.rb +0 -57
  518. data/test/stub/rails4.1/db/seeds.rb +0 -7
  519. data/test/stub/rails4.1/lib/assets/.keep +0 -0
  520. data/test/stub/rails4.1/lib/tasks/.keep +0 -0
  521. data/test/stub/rails4.1/log/.keep +0 -0
  522. data/test/stub/rails4.1/public/404.html +0 -58
  523. data/test/stub/rails4.1/public/422.html +0 -58
  524. data/test/stub/rails4.1/public/500.html +0 -57
  525. data/test/stub/rails4.1/public/favicon.ico +0 -0
  526. data/test/stub/rails4.1/public/robots.txt +0 -5
  527. data/test/stub/rails4.1/test/controllers/.keep +0 -0
  528. data/test/stub/rails4.1/test/fixtures/.keep +0 -0
  529. data/test/stub/rails4.1/test/helpers/.keep +0 -0
  530. data/test/stub/rails4.1/test/integration/.keep +0 -0
  531. data/test/stub/rails4.1/test/mailers/.keep +0 -0
  532. data/test/stub/rails4.1/test/models/.keep +0 -0
  533. data/test/stub/rails4.1/test/test_helper.rb +0 -15
  534. data/test/stub/rails4.1/vendor/assets/javascripts/.keep +0 -0
  535. data/test/stub/rails4.1/vendor/assets/stylesheets/.keep +0 -0
  536. data/test/stub/start_error.pl +0 -24
  537. data/test/stub/upload_data.txt +0 -494
  538. data/test/stub/wsgi/passenger_wsgi.py +0 -212
  539. data/test/stub/wsgi/public/.gitignore +0 -0
  540. data/test/stub/wsgi/tmp/.gitignore +0 -0
  541. data/test/support/allocate_memory.c +0 -14
  542. data/test/support/apache2_controller.rb +0 -258
  543. data/test/support/multipart.rb +0 -62
  544. data/test/support/nginx_controller.rb +0 -97
  545. data/test/support/placebo-preloader.rb +0 -88
  546. data/test/support/test_helper.rb +0 -455
  547. data/test/support/valgrind.h +0 -2539
  548. data/test/tut/tut.h +0 -1310
  549. data/test/tut/tut_reporter.h +0 -256
  550. data/test/valgrind-osx.supp +0 -7
@@ -1,322 +0,0 @@
1
- #include "TestSupport.h"
2
- #include <ServerKit/HttpRequest.h>
3
- #include <MemoryKit/palloc.h>
4
- #include <agents/HelperAgent/RequestHandler/Request.h>
5
- #include <agents/HelperAgent/RequestHandler/AppResponse.h>
6
- #include <agents/HelperAgent/ResponseCache.h>
7
-
8
- using namespace Passenger;
9
- using namespace Passenger::ServerKit;
10
- using namespace std;
11
-
12
- namespace tut {
13
- typedef ResponseCache<Request> ResponseCacheType;
14
-
15
- struct ResponseCacheTest {
16
- ResponseCacheType responseCache;
17
- Request req;
18
- StaticString defaultVaryTurbocacheByCookie;
19
-
20
- ResponseCacheTest() {
21
- req.httpMajor = 1;
22
- req.httpMinor = 0;
23
- req.httpState = Request::COMPLETE;
24
- req.bodyType = Request::RBT_NO_BODY;
25
- req.method = HTTP_GET;
26
- req.wantKeepAlive = false;
27
- req.responseBegun = false;
28
- req.client = NULL;
29
- req.pool = psg_create_pool(PSG_DEFAULT_POOL_SIZE);
30
- req.hooks.impl = NULL;
31
- req.hooks.userData = NULL;
32
- psg_lstr_init(&req.path);
33
- psg_lstr_append(&req.path, req.pool, "/");
34
- req.bodyAlreadyRead = 0;
35
- req.queryStringIndex = -1;
36
- req.bodyError = 0;
37
-
38
- req.startedAt = 0;
39
- req.state = Request::ANALYZING_REQUEST;
40
- req.dechunkResponse = false;
41
- req.requestBodyBuffering = false;
42
- req.https = false;
43
- req.stickySession = false;
44
- req.halfCloseAppConnection = false;
45
- req.sessionCheckoutTry = 0;
46
- req.strip100ContinueHeader = false;
47
- req.hasPragmaHeader = false;
48
- req.host = createHostString();
49
- req.bodyBytesBuffered = 0;
50
- req.cacheControl = NULL;
51
- req.varyCookie = NULL;
52
-
53
- req.appResponse.httpMajor = 1;
54
- req.appResponse.httpMinor = 1;
55
- req.appResponse.httpState = AppResponse::COMPLETE;
56
- req.appResponse.wantKeepAlive = false;
57
- req.appResponse.oneHundredContinueSent = false;
58
- req.appResponse.bodyType = AppResponse::RBT_NO_BODY;
59
- req.appResponse.statusCode = 200;
60
- req.appResponse.bodyAlreadyRead = 0;
61
- req.appResponse.date = NULL;
62
- req.appResponse.setCookie = NULL;
63
- req.appResponse.cacheControl = NULL;
64
- req.appResponse.expiresHeader = NULL;
65
- req.appResponse.lastModifiedHeader = NULL;
66
- req.appResponse.headerCacheBuffers = NULL;
67
- req.appResponse.nHeaderCacheBuffers = 0;
68
- psg_lstr_init(&req.appResponse.bodyCacheBuffer);
69
- }
70
-
71
- ~ResponseCacheTest() {
72
- psg_destroy_pool(req.pool);
73
- }
74
-
75
- LString *createHostString() {
76
- LString *str = (LString *) psg_palloc(req.pool, sizeof(LString));
77
- psg_lstr_init(str);
78
- psg_lstr_append(str, req.pool, "foo.com");
79
- return str;
80
- }
81
-
82
- Header *createHeader(const HashedStaticString &key, const StaticString &val) {
83
- Header *header = (Header *) psg_palloc(req.pool, sizeof(Header));
84
- psg_lstr_init(&header->key);
85
- psg_lstr_init(&header->val);
86
- psg_lstr_append(&header->key, req.pool, key.data(), key.size());
87
- psg_lstr_append(&header->val, req.pool, val.data(), val.size());
88
- header->hash = key.hash();
89
- return header;
90
- }
91
-
92
- void initCacheableResponse() {
93
- req.appResponse.headers.insert(createHeader(
94
- "cache-control", "public,max-age=99999"),
95
- req.pool);
96
- }
97
-
98
- void initUncacheableResponse() {
99
- req.appResponse.headers.insert(createHeader(
100
- "cache-control", "private"),
101
- req.pool);
102
- }
103
- };
104
-
105
- DEFINE_TEST_GROUP(ResponseCacheTest);
106
-
107
-
108
- /***** Preparation *****/
109
-
110
- TEST_METHOD(1) {
111
- set_test_name("It works on a GET request with no body");
112
- ensure(responseCache.prepareRequest(this, &req));
113
- }
114
-
115
- TEST_METHOD(2) {
116
- set_test_name("It fails on upgraded requests");
117
- req.bodyType = Request::RBT_UPGRADE;
118
- ensure(!responseCache.prepareRequest(this, &req));
119
- ensure_equals(req.cacheKey.size(), 0u);
120
- }
121
-
122
- TEST_METHOD(3) {
123
- set_test_name("It fails on requests without a host name");
124
- req.host = NULL;
125
- ensure(!responseCache.prepareRequest(this, &req));
126
- ensure_equals(req.cacheKey.size(), 0u);
127
- }
128
-
129
- TEST_METHOD(4) {
130
- set_test_name("It fails if the path is too long");
131
- psg_lstr_append(&req.path, req.pool, "fooooooooooooooooooooooooooo"
132
- "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
133
- "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
134
- "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
135
- "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
136
- "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
137
- "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
138
- "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo");
139
- ensure(!responseCache.prepareRequest(this, &req));
140
- ensure_equals(req.cacheKey.size(), 0u);
141
- }
142
-
143
- TEST_METHOD(7) {
144
- set_test_name("It generates a cache key on success");
145
- ensure(responseCache.prepareRequest(this, &req));
146
- ensure(req.cacheKey.size() > 0);
147
- }
148
-
149
-
150
- /***** Checking whether request should be fetched from cache *****/
151
-
152
- TEST_METHOD(15) {
153
- set_test_name("It succeeds on GET requests");
154
- ensure(responseCache.prepareRequest(this, &req));
155
- ensure(responseCache.requestAllowsFetching(&req));
156
- }
157
-
158
- TEST_METHOD(16) {
159
- set_test_name("It succeeds on HEAD requests");
160
- req.method = HTTP_HEAD;
161
- ensure(responseCache.prepareRequest(this, &req));
162
- ensure(responseCache.requestAllowsFetching(&req));
163
- }
164
-
165
- TEST_METHOD(17) {
166
- set_test_name("It fails on POST requests");
167
- req.method = HTTP_POST;
168
- ensure("(1)", responseCache.prepareRequest(this, &req));
169
- ensure("(2)", !responseCache.requestAllowsFetching(&req));
170
- }
171
-
172
- TEST_METHOD(18) {
173
- set_test_name("It fails on non-GET and non-HEAD requests");
174
- req.method = HTTP_OPTIONS;
175
- ensure("(1)", responseCache.prepareRequest(this, &req));
176
- ensure("(2)", !responseCache.requestAllowsFetching(&req));
177
- }
178
-
179
- TEST_METHOD(19) {
180
- set_test_name("It fails if the request has a Cache-Control header");
181
- req.headers.insert(createHeader(
182
- "cache-control", "xyz"),
183
- req.pool);
184
- ensure("(1)", responseCache.prepareRequest(this, &req));
185
- ensure("(2)", !responseCache.requestAllowsFetching(&req));
186
- }
187
-
188
- TEST_METHOD(20) {
189
- set_test_name("It fails if the request has a Pragma header");
190
- req.headers.insert(createHeader(
191
- "pragma", "xyz"),
192
- req.pool);
193
- ensure("(1)", responseCache.prepareRequest(this, &req));
194
- ensure("(2)", !responseCache.requestAllowsFetching(&req));
195
- }
196
-
197
-
198
- /***** Checking whether request should be stored to cache *****/
199
-
200
- TEST_METHOD(30) {
201
- set_test_name("It fails on HEAD requests");
202
- initCacheableResponse();
203
- req.method = HTTP_HEAD;
204
- ensure("(1)", responseCache.prepareRequest(this, &req));
205
- ensure("(2)", !responseCache.requestAllowsStoring(&req));
206
- }
207
-
208
- TEST_METHOD(31) {
209
- set_test_name("It fails on all non-GET requests");
210
- initCacheableResponse();
211
- req.method = HTTP_POST;
212
- ensure("(1)", responseCache.prepareRequest(this, &req));
213
- ensure("(2)", !responseCache.requestAllowsStoring(&req));
214
- }
215
-
216
- TEST_METHOD(32) {
217
- set_test_name("It fails if the request's Cache-Control header contains no-store");
218
- initCacheableResponse();
219
- req.headers.insert(createHeader(
220
- "cache-control", "no-store"),
221
- req.pool);
222
- ensure("(1)", responseCache.prepareRequest(this, &req));
223
- ensure("(2)", !responseCache.requestAllowsStoring(&req));
224
- }
225
-
226
- TEST_METHOD(33) {
227
- set_test_name("It fails if the request is not default cacheable");
228
- req.appResponse.statusCode = 205;
229
- ensure("(1)", responseCache.prepareRequest(this, &req));
230
- ensure("(2)", responseCache.requestAllowsStoring(&req));
231
- ensure("(3)", !responseCache.prepareRequestForStoring(&req));
232
- }
233
-
234
- TEST_METHOD(34) {
235
- set_test_name("It fails if the request is default cacheable, but the response has "
236
- "no Cache-Control and no Expires header that allow caching");
237
- ensure_equals(req.appResponse.statusCode, 200);
238
- ensure("(1)", responseCache.prepareRequest(this, &req));
239
- ensure("(2)", responseCache.requestAllowsStoring(&req));
240
- ensure("(3)", !responseCache.prepareRequestForStoring(&req));
241
- }
242
-
243
- TEST_METHOD(35) {
244
- set_test_name("It succeeds if the response contains a Cache-Control header with public directive");
245
- req.appResponse.headers.insert(createHeader(
246
- "cache-control", "public"),
247
- req.pool);
248
- ensure("(1)", responseCache.prepareRequest(this, &req));
249
- ensure("(2)", responseCache.requestAllowsStoring(&req));
250
- ensure("(3)", responseCache.prepareRequestForStoring(&req));
251
- }
252
-
253
- TEST_METHOD(36) {
254
- set_test_name("It succeeds if the response contains a Cache-Control header with max-age directive");
255
- req.appResponse.headers.insert(createHeader(
256
- "cache-control", "max-age=999"),
257
- req.pool);
258
- ensure("(1)", responseCache.prepareRequest(this, &req));
259
- ensure("(2)", responseCache.requestAllowsStoring(&req));
260
- ensure("(3)", responseCache.prepareRequestForStoring(&req));
261
- }
262
-
263
- TEST_METHOD(37) {
264
- set_test_name("It succeeds if the response contains an Expires header");
265
- req.appResponse.headers.insert(createHeader(
266
- "expires", "Tue, 01 Jan 2030 00:00:00 GMT"),
267
- req.pool);
268
- ensure("(1)", responseCache.prepareRequest(this, &req));
269
- ensure("(2)", responseCache.requestAllowsStoring(&req));
270
- ensure("(3)", responseCache.prepareRequestForStoring(&req));
271
- }
272
-
273
- TEST_METHOD(38) {
274
- set_test_name("It fails if the response's Cache-Control header contains no-store");
275
- req.appResponse.headers.insert(createHeader(
276
- "cache-control", "no-store"),
277
- req.pool);
278
- ensure("(1)", responseCache.prepareRequest(this, &req));
279
- ensure("(2)", responseCache.requestAllowsStoring(&req));
280
- ensure("(3)", !responseCache.prepareRequestForStoring(&req));
281
- }
282
-
283
- TEST_METHOD(45) {
284
- set_test_name("It fails if the response's Cache-Control header contains private");
285
- req.appResponse.headers.insert(createHeader(
286
- "cache-control", "private"),
287
- req.pool);
288
- ensure("(1)", responseCache.prepareRequest(this, &req));
289
- ensure("(2)", responseCache.requestAllowsStoring(&req));
290
- ensure("(3)", !responseCache.prepareRequestForStoring(&req));
291
- }
292
-
293
- TEST_METHOD(46) {
294
- set_test_name("It fails if the request has a Authorization header");
295
- req.headers.insert(createHeader(
296
- "authorization", "foo"),
297
- req.pool);
298
- ensure("(1)", responseCache.prepareRequest(this, &req));
299
- ensure("(2)", responseCache.requestAllowsStoring(&req));
300
- ensure("(3)", !responseCache.prepareRequestForStoring(&req));
301
- }
302
-
303
- TEST_METHOD(47) {
304
- set_test_name("It fails if the response has a Vary header");
305
- req.appResponse.headers.insert(createHeader(
306
- "vary", "foo"),
307
- req.pool);
308
- ensure("(1)", responseCache.prepareRequest(this, &req));
309
- ensure("(2)", responseCache.requestAllowsStoring(&req));
310
- ensure("(3)", !responseCache.prepareRequestForStoring(&req));
311
- }
312
-
313
- TEST_METHOD(48) {
314
- set_test_name("It fails if the response has a WWW-Authenticate header");
315
- req.appResponse.headers.insert(createHeader(
316
- "www-authenticate", "foo"),
317
- req.pool);
318
- ensure("(1)", responseCache.prepareRequest(this, &req));
319
- ensure("(2)", responseCache.requestAllowsStoring(&req));
320
- ensure("(3)", !responseCache.prepareRequestForStoring(&req));
321
- }
322
- }
@@ -1,1467 +0,0 @@
1
- #include <TestSupport.h>
2
- #include <BackgroundEventLoop.h>
3
- #include <ServerKit/Channel.h>
4
- #include <Constants.h>
5
- #include <Utils.h>
6
- #include <Utils/StrIntUtils.h>
7
-
8
- using namespace Passenger;
9
- using namespace Passenger::ServerKit;
10
- using namespace Passenger::MemoryKit;
11
- using namespace std;
12
-
13
- namespace tut {
14
- #define CONSUME_FULLY -2
15
-
16
- struct ServerKit_ChannelTest: public ServerKit::Hooks {
17
- BackgroundEventLoop bg;
18
- ServerKit::Context context;
19
- Channel channel;
20
- boost::mutex syncher;
21
- string log;
22
- int toConsume;
23
- bool endConsume;
24
- unsigned int counter, idleCount, endAcked, bytesConsumed;
25
- Channel::State lastState;
26
-
27
- ServerKit_ChannelTest()
28
- : bg(),
29
- context(bg.safe),
30
- channel(&context)
31
- {
32
- channel.dataCallback = dataCallback;
33
- channel.consumedCallback = consumedCallback;
34
- channel.hooks = this;
35
- Hooks::impl = NULL;
36
- Hooks::userData = NULL;
37
- toConsume = CONSUME_FULLY;
38
- endConsume = false;
39
- counter = 0;
40
- idleCount = 0;
41
- endAcked = 0;
42
- bytesConsumed = 0;
43
- lastState = Channel::IDLE;
44
- bg.start();
45
- }
46
-
47
- ~ServerKit_ChannelTest() {
48
- channel.deinitialize(); // Cancel any event loop next tick callbacks.
49
- setLogLevel(DEFAULT_LOG_LEVEL);
50
- }
51
-
52
- static Channel::Result dataCallback(Channel *channel, const mbuf &buffer, int errcode) {
53
- ServerKit_ChannelTest *self = (ServerKit_ChannelTest *) channel->hooks;
54
- boost::lock_guard<boost::mutex> l(self->syncher);
55
- if (errcode == 0) {
56
- self->counter++;
57
- if (buffer.empty()) {
58
- self->log.append("EOF\n");
59
- } else {
60
- StaticString str(buffer.start, buffer.size());
61
- self->log.append("Data: " + cEscapeString(str) + "\n");
62
- }
63
- } else {
64
- self->log.append("Error: " + toString(errcode) + "\n");
65
- }
66
- if (self->toConsume == CONSUME_FULLY) {
67
- return Channel::Result(buffer.size(), self->endConsume);
68
- } else {
69
- return Channel::Result(self->toConsume, self->endConsume);
70
- }
71
- }
72
-
73
- static void consumedCallback(Channel *channel, unsigned int size) {
74
- ServerKit_ChannelTest *self = (ServerKit_ChannelTest *) channel->hooks;
75
- boost::lock_guard<boost::mutex> l(self->syncher);
76
- self->bytesConsumed += size;
77
- if (channel->isIdle()) {
78
- self->idleCount++;
79
- } else if (channel->endAcked()) {
80
- self->endAcked++;
81
- }
82
- }
83
-
84
- unsigned int getCounter() {
85
- boost::lock_guard<boost::mutex> l(syncher);
86
- return counter;
87
- }
88
-
89
- void startChannel() {
90
- bg.safe->runLater(boost::bind(&ServerKit_ChannelTest::realStartChannel, this));
91
- }
92
-
93
- void realStartChannel() {
94
- channel.start();
95
- }
96
-
97
- void stopChannel() {
98
- bg.safe->runLater(boost::bind(&ServerKit_ChannelTest::realStopChannel, this));
99
- }
100
-
101
- void realStopChannel() {
102
- channel.stop();
103
- }
104
-
105
- bool channelIsStarted() {
106
- bool result;
107
- bg.safe->runSync(boost::bind(&ServerKit_ChannelTest::realChannelIsStarted, this, &result));
108
- return result;
109
- }
110
-
111
- void realChannelIsStarted(bool *result) {
112
- *result = channel.isStarted();
113
- }
114
-
115
- bool channelHasError() {
116
- bool result;
117
- bg.safe->runSync(boost::bind(&ServerKit_ChannelTest::realChannelHasError, this, &result));
118
- return result;
119
- }
120
-
121
- void realChannelHasError(bool *result) {
122
- *result = channel.hasError();
123
- }
124
-
125
- void feedChannel(const string &data) {
126
- bg.safe->runLater(boost::bind(&ServerKit_ChannelTest::realFeedChannel, this, data));
127
- }
128
-
129
- void realFeedChannel(string data) {
130
- assert(data.size() < context.mbuf_pool.mbuf_block_chunk_size);
131
- mbuf buf = mbuf_get(&context.mbuf_pool);
132
- memcpy(buf.start, data.data(), data.size());
133
- buf = mbuf(buf, 0, (unsigned int) data.size());
134
- channel.feed(buf);
135
- }
136
-
137
- void feedChannelError(int errcode) {
138
- bg.safe->runLater(boost::bind(&ServerKit_ChannelTest::realFeedChannelError,
139
- this, errcode));
140
- }
141
-
142
- void realFeedChannelError(int errcode) {
143
- channel.feedError(errcode);
144
- }
145
-
146
- void channelConsumed(int size, bool end) {
147
- bg.safe->runLater(boost::bind(&ServerKit_ChannelTest::realChannelConsumed,
148
- this, size, end));
149
- }
150
-
151
- void realChannelConsumed(int size, bool end) {
152
- channel.consumed(size, end);
153
- }
154
-
155
- void setChannelDataCallback(const Channel::DataCallback &callback) {
156
- bg.safe->runSync(boost::bind(&ServerKit_ChannelTest::realSetChannelDataCallback,
157
- this, callback));
158
- }
159
-
160
- void realSetChannelDataCallback(Channel::DataCallback callback) {
161
- channel.dataCallback = callback;
162
- }
163
-
164
- Channel::State getChannelState() {
165
- Channel::State result;
166
- bg.safe->runSync(boost::bind(&ServerKit_ChannelTest::realGetChannelState, this, &result));
167
- return result;
168
- }
169
-
170
- void realGetChannelState(Channel::State *result) {
171
- *result = channel.getState();
172
- }
173
-
174
- int getChannelErrcode() {
175
- int result;
176
- bg.safe->runSync(boost::bind(&ServerKit_ChannelTest::realGetChannelErrcode, this, &result));
177
- return result;
178
- }
179
-
180
- void realGetChannelErrcode(int *result) {
181
- *result = channel.getErrcode();
182
- }
183
-
184
- bool channelIsAcceptingInput() {
185
- bool result;
186
- bg.safe->runSync(boost::bind(&ServerKit_ChannelTest::realChannelIsAcceptingInput, this, &result));
187
- return result;
188
- }
189
-
190
- void realChannelIsAcceptingInput(bool *result) {
191
- *result = channel.acceptingInput();
192
- }
193
-
194
- bool channelMayAcceptInputLater() {
195
- bool result;
196
- bg.safe->runSync(boost::bind(&ServerKit_ChannelTest::realChannelMayAcceptInputLater, this, &result));
197
- return result;
198
- }
199
-
200
- void realChannelMayAcceptInputLater(bool *result) {
201
- *result = channel.mayAcceptInputLater();
202
- }
203
-
204
- void logChannelStateLater() {
205
- bg.safe->runLater(boost::bind(&ServerKit_ChannelTest::logChannelState, this));
206
- }
207
-
208
- void logChannelState() {
209
- boost::lock_guard<boost::mutex> l(syncher);
210
- log.append("State: " + toString((int) channel.getState()) + "\n");
211
- }
212
-
213
- void feedSomeDataAndWaitForConsumption() {
214
- feedChannel("aaabbb");
215
- EVENTUALLY(5,
216
- boost::lock_guard<boost::mutex> l(syncher);
217
- result = !log.empty();
218
- );
219
- {
220
- boost::lock_guard<boost::mutex> l(syncher);
221
- ensure_equals(log, "Data: aaabbb\n");
222
- }
223
- EVENTUALLY(5,
224
- result = getChannelState() == Channel::IDLE;
225
- );
226
- }
227
- };
228
-
229
- #define LOCK() boost::unique_lock<boost::mutex> l(syncher)
230
- #define UNLOCK() l.unlock()
231
-
232
- #define DEFINE_DATA_CALLBACK_METHOD(name, code) \
233
- static Channel::Result name(Channel *channel, const mbuf &buffer, int errcode) { \
234
- ServerKit_ChannelTest *self = (ServerKit_ChannelTest *) channel->hooks; \
235
- boost::mutex &syncher = self->syncher; \
236
- /* Shut up compiler warning */ \
237
- (void) syncher; \
238
- code \
239
- }
240
-
241
- DEFINE_TEST_GROUP_WITH_LIMIT(ServerKit_ChannelTest, 100);
242
-
243
-
244
- /***** Initial state *****/
245
-
246
- TEST_METHOD(1) {
247
- set_test_name("It is idle, accepts input, is not error'red and hasn't ended");
248
- ensure_equals(channel.getState(), Channel::IDLE);
249
- ensure(channel.acceptingInput());
250
- ensure(!channel.hasError());
251
- ensure(!channel.ended());
252
- }
253
-
254
- TEST_METHOD(2) {
255
- set_test_name("Upon being fed data, it calls the callback, transitions "
256
- "to the idle state and calls the consumption callback");
257
- feedChannel("aaabbb");
258
- EVENTUALLY(5,
259
- LOCK();
260
- result = !log.empty();
261
- );
262
- {
263
- LOCK();
264
- ensure_equals(log, "Data: aaabbb\n");
265
- ensure_equals(idleCount, 1u);
266
- ensure_equals(bytesConsumed, 6u);
267
- }
268
- EVENTUALLY(5,
269
- result = getChannelState() == Channel::IDLE;
270
- );
271
- }
272
-
273
- TEST_METHOD(3) {
274
- set_test_name("Upon being fed EOF, it calls the callback with an empty buffer "
275
- "and transitions to the EOF state");
276
- feedChannel("");
277
- EVENTUALLY(5,
278
- result = getChannelState() == Channel::EOF_REACHED;
279
- );
280
- {
281
- LOCK();
282
- ensure_equals(log, "EOF\n");
283
- ensure_equals(endAcked, 1u);
284
- ensure_equals(bytesConsumed, 0u);
285
- }
286
- }
287
-
288
- TEST_METHOD(4) {
289
- set_test_name("Upon being fed an error, it calls the callback with an error code "
290
- "and transitions to the EOF state");
291
- feedChannelError(EIO);
292
- EVENTUALLY(5,
293
- result = getChannelState() == Channel::EOF_REACHED;
294
- );
295
- {
296
- LOCK();
297
- ensure_equals(log, "Error: " + toString(EIO) + "\n");
298
- ensure_equals(endAcked, 1u);
299
- ensure_equals(bytesConsumed, 0u);
300
- }
301
- }
302
-
303
-
304
- /***** When the callback is done consuming data and the Channel is now idle *****/
305
-
306
- TEST_METHOD(10) {
307
- set_test_name("It is idle and accepts input");
308
-
309
- feedSomeDataAndWaitForConsumption();
310
- ensure_equals(getChannelState(), Channel::IDLE);
311
- ensure(channelIsAcceptingInput());
312
- }
313
-
314
- TEST_METHOD(11) {
315
- set_test_name("It calls the consumption callback");
316
-
317
- feedSomeDataAndWaitForConsumption();
318
- LOCK();
319
- ensure_equals(idleCount, 1u);
320
- }
321
-
322
- TEST_METHOD(12) {
323
- set_test_name("Upon being fed data, it calls the callback and transitions "
324
- "to the idle state");
325
-
326
- feedSomeDataAndWaitForConsumption();
327
- feedChannel("aaabbb");
328
- EVENTUALLY(5,
329
- LOCK();
330
- result = log.find("Data: aaabbb\n") != string::npos;
331
- );
332
- EVENTUALLY(5,
333
- result = getChannelState() == Channel::IDLE;
334
- );
335
- }
336
-
337
- TEST_METHOD(13) {
338
- set_test_name("Upon being fed EOF, it calls the callback with an empty "
339
- "buffer and transitions to the EOF state");
340
-
341
- feedSomeDataAndWaitForConsumption();
342
- feedChannel("");
343
- EVENTUALLY(5,
344
- LOCK();
345
- result = log.find("EOF") != string::npos;
346
- );
347
- {
348
- LOCK();
349
- ensure_equals(log,
350
- "Data: aaabbb\n"
351
- "EOF\n");
352
- }
353
- EVENTUALLY(5,
354
- result = getChannelState() == Channel::EOF_REACHED;
355
- );
356
- }
357
-
358
- TEST_METHOD(14) {
359
- set_test_name("Upon being fed an error, it calls the callback with an "
360
- "error code and transitions to the EOF state");
361
-
362
- feedSomeDataAndWaitForConsumption();
363
- feedChannelError(EIO);
364
- EVENTUALLY(5,
365
- LOCK();
366
- result = log.find("Error") != string::npos;
367
- );
368
- {
369
- LOCK();
370
- ensure_equals(log,
371
- "Data: aaabbb\n"
372
- "Error: " + toString(EIO) + "\n");
373
- }
374
- EVENTUALLY(5,
375
- result = getChannelState() == Channel::EOF_REACHED;
376
- );
377
- }
378
-
379
-
380
- /***** When the callback is in progress *****/
381
-
382
- DEFINE_DATA_CALLBACK_METHOD(test_20_callback,
383
- LOCK();
384
- self->lastState = self->channel.getState();
385
- return Channel::Result(buffer.size(), false);
386
- );
387
-
388
- TEST_METHOD(20) {
389
- set_test_name("It is in the calling state");
390
-
391
- setChannelDataCallback(test_20_callback);
392
- feedChannel("abc");
393
- EVENTUALLY(5,
394
- result = getChannelState() == Channel::IDLE;
395
- );
396
- {
397
- LOCK();
398
- ensure_equals(lastState, Channel::CALLING);
399
- }
400
- }
401
-
402
- DEFINE_DATA_CALLBACK_METHOD(test_21_callback,
403
- LOCK();
404
- self->counter++;
405
- if (self->counter == 1) {
406
- self->log.append("Feeding error\n");
407
- UNLOCK();
408
- self->channel.feedError(EIO);
409
- } else {
410
- self->log.append("Received error: " + toString(errcode) + "\n");
411
- UNLOCK();
412
- }
413
- return Channel::Result(buffer.size(), false);
414
- );
415
-
416
- TEST_METHOD(21) {
417
- set_test_name("Upon being fed an error, it transitions to the EOF state immediately "
418
- "and doesn't call the callback with an error code");
419
-
420
- setChannelDataCallback(test_21_callback);
421
- feedChannel("abc");
422
- EVENTUALLY(5,
423
- result = getChannelState() == Channel::EOF_REACHED;
424
- );
425
- {
426
- LOCK();
427
- ensure_equals(log,
428
- "Feeding error\n");
429
- }
430
- }
431
-
432
- DEFINE_DATA_CALLBACK_METHOD(test_22_callback,
433
- self->channel.start();
434
- LOCK();
435
- self->log.append("Channel state: " + toString(self->channel.getState()) + "\n");
436
- self->log.append("Channel started: " + toString(self->channel.isStarted()) + "\n");
437
- return Channel::Result(buffer.size(), false);
438
- );
439
-
440
- TEST_METHOD(22) {
441
- set_test_name("Upon calling start(), nothing happens");
442
-
443
- setChannelDataCallback(test_22_callback);
444
- feedChannel("abc");
445
- EVENTUALLY(5,
446
- result = getChannelState() == Channel::IDLE;
447
- );
448
- {
449
- LOCK();
450
- ensure_equals(log,
451
- "Channel state: " + toString(Channel::CALLING) + "\n"
452
- "Channel started: 1\n");
453
- }
454
- }
455
-
456
- DEFINE_DATA_CALLBACK_METHOD(test_23_callback,
457
- self->channel.stop();
458
- return Channel::Result(buffer.size(), false);
459
- );
460
-
461
- TEST_METHOD(23) {
462
- set_test_name("Upon calling stop(), it transitions to the stopped state");
463
-
464
- setChannelDataCallback(test_23_callback);
465
- feedChannel("abc");
466
- EVENTUALLY(5,
467
- result = getChannelState() == Channel::STOPPED;
468
- );
469
- SHOULD_NEVER_HAPPEN(100,
470
- result = getChannelState() != Channel::STOPPED;
471
- );
472
- }
473
-
474
- DEFINE_DATA_CALLBACK_METHOD(test_24_callback,
475
- self->channel.stop();
476
- {
477
- LOCK();
478
- self->log.append("Channel state: " + toString(self->channel.getState()) + "\n");
479
- self->log.append("Channel started: " + toString(self->channel.isStarted()) + "\n");
480
- }
481
- self->channel.start();
482
- {
483
- LOCK();
484
- self->log.append("Channel state: " + toString(self->channel.getState()) + "\n");
485
- self->log.append("Channel started: " + toString(self->channel.isStarted()) + "\n");
486
- }
487
- return Channel::Result(buffer.size(), false);
488
- );
489
-
490
- TEST_METHOD(24) {
491
- set_test_name("Upon calling stop() then start(), it transitions to the calling state");
492
-
493
- setChannelDataCallback(test_24_callback);
494
- feedChannel("abc");
495
- EVENTUALLY(5,
496
- result = getChannelState() == Channel::IDLE;
497
- );
498
- {
499
- LOCK();
500
- ensure_equals(log,
501
- "Channel state: " + toString(Channel::STOPPED_WHILE_CALLING) + "\n"
502
- "Channel started: 0\n"
503
- "Channel state: " + toString(Channel::CALLING) + "\n"
504
- "Channel started: 1\n");
505
- }
506
- }
507
-
508
- DEFINE_DATA_CALLBACK_METHOD(test_25_callback,
509
- LOCK();
510
- self->counter++;
511
- if (self->counter == 1) {
512
- UNLOCK();
513
- self->channel.stop();
514
- self->channel.start();
515
- } else {
516
- StaticString str(buffer.start, buffer.size());
517
- self->log.append("Data: " + cEscapeString(str) + "\n");
518
- self->log.append("Error: " + toString(errcode) + "\n");
519
- }
520
- return Channel::Result(buffer.size(), false);
521
- );
522
-
523
- TEST_METHOD(25) {
524
- set_test_name("Upon calling stop() then start(), it calls the callback next time data is fed");
525
-
526
- setChannelDataCallback(test_25_callback);
527
- feedChannel("abc");
528
- EVENTUALLY(5,
529
- result = getChannelState() == Channel::IDLE;
530
- );
531
- feedChannel("def");
532
- EVENTUALLY(5,
533
- result = getChannelState() == Channel::IDLE;
534
- );
535
- {
536
- LOCK();
537
- ensure_equals(log,
538
- "Data: def\n"
539
- "Error: 0\n");
540
- }
541
- }
542
-
543
- DEFINE_DATA_CALLBACK_METHOD(test_26_27_callback,
544
- LOCK();
545
- self->counter++;
546
- if (self->counter == 1) {
547
- UNLOCK();
548
- self->channel.stop();
549
- self->channel.start();
550
- } else {
551
- StaticString str(buffer.start, buffer.size());
552
- self->log.append("Data: " + cEscapeString(str) + "\n");
553
- self->log.append("Error: " + toString(errcode) + "\n");
554
- }
555
- return Channel::Result(buffer.size(), false);
556
- );
557
-
558
- TEST_METHOD(26) {
559
- set_test_name("Upon calling stop() then start(), it calls the callback next time EOF is fed");
560
-
561
- setChannelDataCallback(test_26_27_callback);
562
- feedChannel("abc");
563
- EVENTUALLY(5,
564
- result = getChannelState() == Channel::IDLE;
565
- );
566
- feedChannel("");
567
- EVENTUALLY(5,
568
- result = getChannelState() == Channel::EOF_REACHED;
569
- );
570
- {
571
- LOCK();
572
- ensure_equals(log,
573
- "Data: \n"
574
- "Error: 0\n");
575
- }
576
- }
577
-
578
- TEST_METHOD(27) {
579
- set_test_name("Upon calling stop() then start(), it calls the callback next time an error is fed");
580
-
581
- setChannelDataCallback(test_26_27_callback);
582
- feedChannel("abc");
583
- EVENTUALLY(5,
584
- result = getChannelState() == Channel::IDLE;
585
- );
586
- feedChannelError(EIO);
587
- EVENTUALLY(5,
588
- result = getChannelState() == Channel::EOF_REACHED;
589
- );
590
- {
591
- LOCK();
592
- ensure_equals(log,
593
- "Data: \n"
594
- "Error: " + toString(EIO) + "\n");
595
- }
596
- }
597
-
598
- DEFINE_DATA_CALLBACK_METHOD(test_28_callback,
599
- self->channel.deinitialize();
600
- LOCK();
601
- self->log.append("Buffer size: " + toString(buffer.size()));
602
- return Channel::Result(buffer.size(), false);
603
- );
604
-
605
- TEST_METHOD(28) {
606
- set_test_name("Deinitializing the channel doesn't invalidate the buffer argument");
607
-
608
- setChannelDataCallback(test_28_callback);
609
- feedChannel("abc");
610
- EVENTUALLY(5,
611
- result = !log.empty();
612
- );
613
- ensure_equals(log, "Buffer size: 3");
614
- }
615
-
616
-
617
- /***** When the callback is not in progress *****/
618
-
619
- TEST_METHOD(30) {
620
- set_test_name("Upon calling start(), nothing happens");
621
-
622
- startChannel();
623
- ensure_equals(getChannelState(), Channel::IDLE);
624
- ensure(channelIsStarted());
625
- }
626
-
627
- TEST_METHOD(31) {
628
- set_test_name("Upon calling stop(), it transitions to the stopped state");
629
-
630
- stopChannel();
631
- ensure_equals(getChannelState(), Channel::STOPPED);
632
- ensure(!channelIsStarted());
633
- }
634
-
635
- static void test_32_callback(ServerKit_ChannelTest *self) {
636
- self->channel.stop();
637
- self->channel.start();
638
- {
639
- boost::mutex &syncher = self->syncher;
640
- LOCK();
641
- self->log.append("Channel state: " + toString(self->channel.getState()) + "\n");
642
- }
643
- }
644
-
645
- TEST_METHOD(32) {
646
- set_test_name("Upon calling stop() then start(), it transitions to the idle state");
647
-
648
- bg.safe->runLater(boost::bind(test_32_callback, this));
649
- EVENTUALLY(5,
650
- result = getChannelState() == Channel::IDLE;
651
- );
652
- {
653
- LOCK();
654
- ensure_equals(log,
655
- "Channel state: " + toString(Channel::IDLE) + "\n");
656
- }
657
- }
658
-
659
- static void test_33_callback(ServerKit_ChannelTest *self) {
660
- self->channel.stop();
661
- self->channel.start();
662
- {
663
- boost::mutex &syncher = self->syncher;
664
- LOCK();
665
- self->log.append("Channel state: " + toString(self->channel.getState()) + "\n");
666
- }
667
- self->channel.feed(mbuf("abc"));
668
- }
669
-
670
- TEST_METHOD(33) {
671
- set_test_name("Upon calling stop() then start(), it calls the callback next time data is fed");
672
-
673
- bg.safe->runLater(boost::bind(test_33_callback, this));
674
- EVENTUALLY(5,
675
- result = getChannelState() == Channel::IDLE;
676
- );
677
- {
678
- LOCK();
679
- ensure_equals(log,
680
- "Channel state: " + toString(Channel::IDLE) + "\n"
681
- "Data: abc\n");
682
- ensure_equals(counter, 1u);
683
- }
684
- }
685
-
686
- static void test_34_callback(ServerKit_ChannelTest *self) {
687
- self->channel.stop();
688
- self->channel.start();
689
- {
690
- boost::mutex &syncher = self->syncher;
691
- LOCK();
692
- self->log.append("Channel state: " + toString(self->channel.getState()) + "\n");
693
- }
694
- self->channel.feed(mbuf());
695
- }
696
-
697
- TEST_METHOD(34) {
698
- set_test_name("Upon calling stop() then start(), it calls the callback next time EOF is fed");
699
-
700
- bg.safe->runLater(boost::bind(test_34_callback, this));
701
- EVENTUALLY(5,
702
- result = getChannelState() == Channel::EOF_REACHED;
703
- );
704
- {
705
- LOCK();
706
- ensure_equals(log,
707
- "Channel state: " + toString(Channel::IDLE) + "\n"
708
- "EOF\n");
709
- ensure_equals(counter, 1u);
710
- }
711
- }
712
-
713
- static void test_35_callback(ServerKit_ChannelTest *self) {
714
- self->channel.stop();
715
- self->channel.start();
716
- {
717
- boost::mutex &syncher = self->syncher;
718
- LOCK();
719
- self->log.append("Channel state: " + toString(self->channel.getState()) + "\n");
720
- }
721
- self->channel.feedError(EIO);
722
- }
723
-
724
- TEST_METHOD(35) {
725
- set_test_name("Upon calling stop() then start(), it calls the callback next time an error is fed");
726
-
727
- bg.safe->runLater(boost::bind(test_35_callback, this));
728
- EVENTUALLY(5,
729
- result = getChannelState() == Channel::EOF_REACHED;
730
- );
731
- {
732
- LOCK();
733
- ensure_equals(log,
734
- "Channel state: " + toString(Channel::IDLE) + "\n"
735
- "Error: " + toString(EIO) + "\n");
736
- ensure_equals(counter, 0u);
737
- }
738
- }
739
-
740
-
741
- /***** If the callback immediately consumed the buffer partially *****/
742
-
743
- TEST_METHOD(40) {
744
- set_test_name("If the callback has ended consumption, the Channel transitions "
745
- "to the 'EOF reached' state and calls the endAck callback");
746
-
747
- {
748
- LOCK();
749
- toConsume = 1;
750
- endConsume = true;
751
- }
752
- feedChannel("abc");
753
- EVENTUALLY(5,
754
- result = getChannelState() == Channel::EOF_REACHED;
755
- );
756
- {
757
- LOCK();
758
- ensure_equals(endAcked, 1u);
759
- ensure_equals(log,
760
- "Data: abc\n");
761
- }
762
- }
763
-
764
- TEST_METHOD(41) {
765
- set_test_name("If the callback has not ended consumption, the Channel calls "
766
- "the callback again with the remainder of the the buffer, until the buffer is fully consumed");
767
-
768
- {
769
- LOCK();
770
- toConsume = 1;
771
- }
772
- feedChannel("abc");
773
- EVENTUALLY(5,
774
- result = getChannelState() == Channel::IDLE;
775
- );
776
- {
777
- LOCK();
778
- ensure_equals(log,
779
- "Data: abc\n"
780
- "Data: bc\n"
781
- "Data: c\n");
782
- }
783
- }
784
-
785
- DEFINE_DATA_CALLBACK_METHOD(test_42_callback,
786
- LOCK();
787
- self->counter++;
788
- if (self->counter != 1) {
789
- UNLOCK();
790
- self->channel.feedError(EIO);
791
- }
792
- return Channel::Result(1, false);
793
- );
794
-
795
- TEST_METHOD(42) {
796
- set_test_name("Upon being fed an error, it transitions to the EOF state immediately, "
797
- "and it won't call the callback with an error code");
798
-
799
- setChannelDataCallback(test_42_callback);
800
- feedChannel("abc");
801
- EVENTUALLY(5,
802
- result = getChannelState() == Channel::EOF_REACHED;
803
- );
804
- {
805
- LOCK();
806
- ensure_equals(counter, 2u);
807
- ensure(channelHasError());
808
- ensure_equals(getChannelErrcode(), EIO);
809
- }
810
- }
811
-
812
- DEFINE_DATA_CALLBACK_METHOD(test_43_callback,
813
- LOCK();
814
- self->counter++;
815
- if (self->counter == 1) {
816
- UNLOCK();
817
- self->channel.stop();
818
- }
819
- return Channel::Result(1, false);
820
- );
821
-
822
- TEST_METHOD(43) {
823
- set_test_name("If stop() was called, it doesn't call the callback with the "
824
- "remainder of the buffer");
825
-
826
- setChannelDataCallback(test_43_callback);
827
- feedChannel("abc");
828
- EVENTUALLY(5,
829
- result = getChannelState() == Channel::STOPPED;
830
- );
831
- {
832
- LOCK();
833
- ensure_equals(counter, 1u);
834
- }
835
- }
836
-
837
- DEFINE_DATA_CALLBACK_METHOD(test_44_callback,
838
- self->channel.stop();
839
- LOCK();
840
- self->counter++;
841
- return Channel::Result(1, true);
842
- );
843
-
844
- TEST_METHOD(44) {
845
- set_test_name("If stop() was called, and the callback has ended consumption, then "
846
- "the Channel transitions to the 'EOF reached' state and calls the endAck callback");
847
-
848
- setChannelDataCallback(test_44_callback);
849
- feedChannel("abc");
850
- EVENTUALLY(5,
851
- result = getChannelState() == Channel::EOF_REACHED;
852
- );
853
- {
854
- LOCK();
855
- ensure_equals(counter, 1u);
856
- ensure_equals(endAcked, 1u);
857
- }
858
- }
859
-
860
- DEFINE_DATA_CALLBACK_METHOD(test_45_callback,
861
- self->channel.stop();
862
- self->channel.start();
863
- LOCK();
864
- self->counter++;
865
- return Channel::Result(1, true);
866
- );
867
-
868
- TEST_METHOD(45) {
869
- set_test_name("If stop() then start() was called, and the channel has ended consumption, "
870
- "then it transitions to the 'EOF reached' state and calls the endAck callback");
871
-
872
- setChannelDataCallback(test_45_callback);
873
- feedChannel("abc");
874
- EVENTUALLY(5,
875
- result = getChannelState() == Channel::EOF_REACHED;
876
- );
877
- {
878
- LOCK();
879
- ensure_equals(counter, 1u);
880
- ensure_equals(endAcked, 1u);
881
- }
882
- }
883
-
884
- DEFINE_DATA_CALLBACK_METHOD(test_46_callback,
885
- LOCK();
886
- StaticString str(buffer.start, buffer.size());
887
- self->counter++;
888
- self->log.append("Data: " + cEscapeString(str) + "\n");
889
- if (self->counter == 1) {
890
- UNLOCK();
891
- self->channel.stop();
892
- self->channel.start();
893
- }
894
- return Channel::Result(1, false);
895
- );
896
-
897
- TEST_METHOD(46) {
898
- set_test_name("If stop() then start() was called, and the channel has not ended consumption, "
899
- "then it calls the callback with the remainder of the data in the next tick");
900
-
901
- setChannelDataCallback(test_46_callback);
902
- feedChannel("abc");
903
- EVENTUALLY(5,
904
- result = getChannelState() == Channel::IDLE;
905
- );
906
- {
907
- LOCK();
908
- ensure_equals(counter, 3u);
909
- ensure_equals(log,
910
- "Data: abc\n"
911
- "Data: bc\n"
912
- "Data: c\n");
913
- }
914
- }
915
-
916
- DEFINE_DATA_CALLBACK_METHOD(test_47_callback,
917
- LOCK();
918
- StaticString str(buffer.start, buffer.size());
919
- self->counter++;
920
- self->log.append("Data: " + cEscapeString(str) + "\n");
921
- if (self->counter == 1) {
922
- UNLOCK();
923
- self->channel.deinitialize();
924
- }
925
- return Channel::Result(1, false);
926
- );
927
-
928
- TEST_METHOD(47) {
929
- set_test_name("If it had been deinitialized in the callback, it doesn't call the "
930
- "callback again");
931
-
932
- setChannelDataCallback(test_47_callback);
933
- feedChannel("abc");
934
- EVENTUALLY(5,
935
- result = getChannelState() == Channel::CALLING;
936
- );
937
- {
938
- LOCK();
939
- ensure_equals(counter, 1u);
940
- ensure_equals(log,
941
- "Data: abc\n");
942
- }
943
- }
944
-
945
- TEST_METHOD(48) {
946
- set_test_name("If the callback has ended consumption, upon fully consuming the buffer, "
947
- "the Channel transitions to the 'EOF reached' state and calls the endAck callback");
948
-
949
- {
950
- LOCK();
951
- endConsume = true;
952
- }
953
- feedChannel("abc");
954
- EVENTUALLY(5,
955
- result = getChannelState() == Channel::EOF_REACHED;
956
- );
957
- {
958
- LOCK();
959
- ensure_equals(counter, 1u);
960
- ensure_equals(endAcked, 1u);
961
- }
962
- }
963
-
964
- TEST_METHOD(49) {
965
- set_test_name("If the callback has not ended consumption, upon fully "
966
- "consuming the buffer, the Channel calls the consumption callback");
967
-
968
- {
969
- LOCK();
970
- toConsume = 1;
971
- }
972
- feedChannel("abc");
973
- EVENTUALLY(5,
974
- result = getChannelState() == Channel::IDLE;
975
- );
976
- {
977
- LOCK();
978
- ensure_equals(counter, 3u);
979
- ensure_equals(idleCount, 1u);
980
- }
981
- }
982
-
983
-
984
- /***** If the callback immediately consumed the buffer fully *****/
985
-
986
- TEST_METHOD(50) {
987
- set_test_name("If the callback has ended consumption, the Channel"
988
- "transitions to the 'EOF reached' state and calls the endAck callback");
989
-
990
- {
991
- LOCK();
992
- endConsume = true;
993
- }
994
- feedChannel("aaabbb");
995
- EVENTUALLY(5,
996
- result = getChannelState() == Channel::EOF_REACHED;
997
- );
998
- {
999
- LOCK();
1000
- ensure_equals(log, "Data: aaabbb\n");
1001
- ensure_equals(endAcked, 1u);
1002
- }
1003
- }
1004
-
1005
- TEST_METHOD(52) {
1006
- set_test_name("If the callback has not ended consumption, "
1007
- "the Channel transitions to the idle state and calls the consumption callback");
1008
-
1009
- feedSomeDataAndWaitForConsumption();
1010
- ensure_equals(getChannelState(), Channel::IDLE);
1011
- ensure_equals(idleCount, 1u);
1012
- }
1013
-
1014
-
1015
-
1016
- /***** If the callback deferred consumption *****/
1017
-
1018
- TEST_METHOD(55) {
1019
- set_test_name("It transitions to the 'waiting for callback' state");
1020
-
1021
- {
1022
- LOCK();
1023
- toConsume = -1;
1024
- }
1025
- feedChannel("abc");
1026
- EVENTUALLY(5,
1027
- result = getChannelState() == Channel::WAITING_FOR_CALLBACK;
1028
- );
1029
- SHOULD_NEVER_HAPPEN(100,
1030
- result = getChannelState() != Channel::WAITING_FOR_CALLBACK;
1031
- );
1032
- }
1033
-
1034
- TEST_METHOD(56) {
1035
- set_test_name("Upon being fed an error, it transitions to the 'EOF waiting' state");
1036
-
1037
- {
1038
- LOCK();
1039
- toConsume = -1;
1040
- }
1041
- feedChannelError(EIO);
1042
- EVENTUALLY(5,
1043
- result = getChannelState() == Channel::EOF_WAITING;
1044
- );
1045
- SHOULD_NEVER_HAPPEN(100,
1046
- result = getChannelState() != Channel::EOF_WAITING;
1047
- );
1048
- ensure_equals(getChannelErrcode(), EIO);
1049
- }
1050
-
1051
- TEST_METHOD(57) {
1052
- set_test_name("When consumed() is called with the end flag, it "
1053
- "transitions to the 'EOF reached' state and calls the endAck callback");
1054
-
1055
- {
1056
- LOCK();
1057
- toConsume = -1;
1058
- }
1059
- feedChannel("abc");
1060
- EVENTUALLY(5,
1061
- result = getChannelState() == Channel::WAITING_FOR_CALLBACK;
1062
- );
1063
-
1064
- channelConsumed(3, true);
1065
- EVENTUALLY(5,
1066
- result = getChannelState() == Channel::EOF_REACHED;
1067
- );
1068
- {
1069
- LOCK();
1070
- ensure_equals(endAcked, 1u);
1071
- }
1072
- }
1073
-
1074
- TEST_METHOD(58) {
1075
- set_test_name("When consumed() is called with the full buffer size, "
1076
- "it transitions to the idle state");
1077
-
1078
- {
1079
- LOCK();
1080
- toConsume = -1;
1081
- }
1082
- feedChannel("abc");
1083
- EVENTUALLY(5,
1084
- result = getChannelState() == Channel::WAITING_FOR_CALLBACK;
1085
- );
1086
-
1087
- channelConsumed(3, false);
1088
- EVENTUALLY(5,
1089
- result = getChannelState() == Channel::IDLE;
1090
- );
1091
- }
1092
-
1093
- TEST_METHOD(59) {
1094
- set_test_name("Upon calling stop(), it transitions to the stopped state");
1095
-
1096
- {
1097
- LOCK();
1098
- toConsume = -1;
1099
- }
1100
- feedChannel("abc");
1101
- EVENTUALLY(5,
1102
- result = getChannelState() == Channel::WAITING_FOR_CALLBACK;
1103
- );
1104
-
1105
- stopChannel();
1106
- EVENTUALLY(5,
1107
- result = getChannelState() == Channel::STOPPED_WHILE_WAITING;
1108
- );
1109
- }
1110
-
1111
- static void test_60_stop_start_channel(ServerKit_ChannelTest *self) {
1112
- self->channel.stop();
1113
- self->channel.start();
1114
- {
1115
- boost::mutex &syncher = self->syncher;
1116
- LOCK();
1117
- self->counter++;
1118
- self->log.append("Channel state: " + toString(self->channel.getState()) + "\n");
1119
- }
1120
- }
1121
-
1122
- TEST_METHOD(60) {
1123
- set_test_name("Upon calling stop() then start(), it transitions to the 'waiting for callback' state");
1124
-
1125
- {
1126
- LOCK();
1127
- toConsume = -1;
1128
- }
1129
- feedChannel("abc");
1130
- EVENTUALLY(5,
1131
- result = getChannelState() == Channel::WAITING_FOR_CALLBACK;
1132
- );
1133
-
1134
- stopChannel();
1135
- EVENTUALLY(5,
1136
- result = getChannelState() == Channel::STOPPED_WHILE_WAITING;
1137
- );
1138
- bg.safe->runLater(boost::bind(test_60_stop_start_channel, this));
1139
- EVENTUALLY(5,
1140
- LOCK();
1141
- result = counter == 2;
1142
- );
1143
- {
1144
- LOCK();
1145
- ensure_equals(log,
1146
- "Data: abc\n"
1147
- "Channel state: " + toString(Channel::WAITING_FOR_CALLBACK) + "\n");
1148
- }
1149
- }
1150
-
1151
- TEST_METHOD(61) {
1152
- set_test_name("Upon calling stop() then start() then feedError(), "
1153
- "it transitions to the EOF state immediately");
1154
-
1155
- {
1156
- LOCK();
1157
- toConsume = -1;
1158
- }
1159
- feedChannel("abc");
1160
- EVENTUALLY(5,
1161
- result = getChannelState() == Channel::WAITING_FOR_CALLBACK;
1162
- );
1163
-
1164
- stopChannel();
1165
- EVENTUALLY(5,
1166
- result = getChannelState() == Channel::STOPPED_WHILE_WAITING;
1167
- );
1168
-
1169
- startChannel();
1170
- EVENTUALLY(5,
1171
- result = getChannelState() == Channel::WAITING_FOR_CALLBACK;
1172
- );
1173
-
1174
- feedChannelError(EIO);
1175
- EVENTUALLY(5,
1176
- result = getChannelState() == Channel::EOF_REACHED;
1177
- );
1178
- SHOULD_NEVER_HAPPEN(100,
1179
- result = getChannelState() != Channel::EOF_REACHED;
1180
- );
1181
- }
1182
-
1183
- TEST_METHOD(62) {
1184
- set_test_name("When consumed() is called with a partial buffer size, "
1185
- "it calls the callback again with the remainder of the buffer");
1186
-
1187
- {
1188
- LOCK();
1189
- toConsume = -1;
1190
- }
1191
- feedChannel("abc");
1192
- EVENTUALLY(5,
1193
- result = getChannelState() == Channel::WAITING_FOR_CALLBACK;
1194
- );
1195
-
1196
- {
1197
- LOCK();
1198
- toConsume = CONSUME_FULLY;
1199
- }
1200
- channelConsumed(2, false);
1201
- EVENTUALLY(5,
1202
- result = getChannelState() == Channel::IDLE;
1203
- );
1204
- {
1205
- LOCK();
1206
- ensure_equals(counter, 2u);
1207
- ensure_equals(log,
1208
- "Data: abc\n"
1209
- "Data: c\n");
1210
- }
1211
- }
1212
-
1213
- TEST_METHOD(63) {
1214
- set_test_name("If stop() was called, and consumed() is called with a partial buffer size, "
1215
- "then it doesn't call the callback");
1216
-
1217
- {
1218
- LOCK();
1219
- toConsume = -1;
1220
- }
1221
- feedChannel("abc");
1222
- EVENTUALLY(5,
1223
- result = getChannelState() == Channel::WAITING_FOR_CALLBACK;
1224
- );
1225
-
1226
- stopChannel();
1227
- EVENTUALLY(5,
1228
- result = getChannelState() == Channel::STOPPED_WHILE_WAITING;
1229
- );
1230
-
1231
- {
1232
- LOCK();
1233
- toConsume = CONSUME_FULLY;
1234
- }
1235
- channelConsumed(2, false);
1236
- SHOULD_NEVER_HAPPEN(100,
1237
- LOCK();
1238
- result = counter > 1;
1239
- );
1240
- ensure_equals(getChannelState(), Channel::STOPPED);
1241
- }
1242
-
1243
- static void test_64_start_channel(ServerKit_ChannelTest *self) {
1244
- self->channel.start();
1245
- {
1246
- boost::mutex &syncher = self->syncher;
1247
- LOCK();
1248
- self->counter++;
1249
- self->log.append("Channel state: " + toString(self->channel.getState()) + "\n");
1250
- }
1251
- }
1252
-
1253
- TEST_METHOD(64) {
1254
- set_test_name("If stop() was called, and consumed() is called with a partial buffer size, "
1255
- "then it calls the callback with the remainder of the data one tick after next time "
1256
- "start() is called");
1257
-
1258
- {
1259
- LOCK();
1260
- toConsume = -1;
1261
- }
1262
- feedChannel("abc");
1263
- EVENTUALLY(5,
1264
- result = getChannelState() == Channel::WAITING_FOR_CALLBACK;
1265
- );
1266
-
1267
- stopChannel();
1268
- EVENTUALLY(5,
1269
- result = getChannelState() == Channel::STOPPED_WHILE_WAITING;
1270
- );
1271
-
1272
- {
1273
- LOCK();
1274
- toConsume = CONSUME_FULLY;
1275
- }
1276
- channelConsumed(2, false);
1277
- bg.safe->runLater(boost::bind(test_64_start_channel, this));
1278
- EVENTUALLY(5,
1279
- result = getChannelState() == Channel::IDLE;
1280
- );
1281
- {
1282
- LOCK();
1283
- ensure_equals(counter, 3u);
1284
- ensure_equals(log,
1285
- "Data: abc\n"
1286
- "Channel state: " + toString(Channel::PLANNING_TO_CALL) + "\n"
1287
- "Data: c\n");
1288
- }
1289
- }
1290
-
1291
- TEST_METHOD(65) {
1292
- set_test_name("If stop() was called, and consumed() is called with a full buffer size, "
1293
- "then it doesn't call the callback");
1294
-
1295
- {
1296
- LOCK();
1297
- toConsume = -1;
1298
- }
1299
- feedChannel("abc");
1300
- EVENTUALLY(5,
1301
- result = getChannelState() == Channel::WAITING_FOR_CALLBACK;
1302
- );
1303
-
1304
- stopChannel();
1305
- EVENTUALLY(5,
1306
- result = getChannelState() == Channel::STOPPED_WHILE_WAITING;
1307
- );
1308
-
1309
- channelConsumed(3, false);
1310
- SHOULD_NEVER_HAPPEN(100,
1311
- LOCK();
1312
- result = counter > 1;
1313
- );
1314
- ensure_equals(getChannelState(), Channel::STOPPED);
1315
- }
1316
-
1317
- static void test_66_start_channel(ServerKit_ChannelTest *self) {
1318
- self->channel.start();
1319
- {
1320
- boost::mutex &syncher = self->syncher;
1321
- LOCK();
1322
- self->counter++;
1323
- self->log.append("Channel state: " + toString(self->channel.getState()) + "\n");
1324
- self->log.append("Idle count so far: " + toString(self->idleCount) + "\n");
1325
- }
1326
- }
1327
-
1328
- TEST_METHOD(66) {
1329
- set_test_name("If stop() was called, and consumed() is called with a full buffer size, "
1330
- "then when start() is called, it transitions to the idle state and calls the consumption callback");
1331
-
1332
- {
1333
- LOCK();
1334
- toConsume = -1;
1335
- }
1336
- feedChannel("abc");
1337
- EVENTUALLY(5,
1338
- result = getChannelState() == Channel::WAITING_FOR_CALLBACK;
1339
- );
1340
-
1341
- stopChannel();
1342
- EVENTUALLY(5,
1343
- result = getChannelState() == Channel::STOPPED_WHILE_WAITING;
1344
- );
1345
-
1346
- channelConsumed(3, false);
1347
- bg.safe->runLater(boost::bind(test_66_start_channel, this));
1348
- EVENTUALLY(5,
1349
- result = getChannelState() == Channel::IDLE;
1350
- );
1351
- {
1352
- LOCK();
1353
- ensure_equals(counter, 2u);
1354
- ensure_equals(idleCount, 1u);
1355
- ensure_equals(log,
1356
- "Data: abc\n"
1357
- "Channel state: " + toString(Channel::IDLE) + "\n"
1358
- "Idle count so far: 1\n");
1359
- }
1360
- }
1361
-
1362
-
1363
- /***** Upon being fed EOF *****/
1364
-
1365
- TEST_METHOD(70) {
1366
- set_test_name("If the callback does not immediately consume the EOF, "
1367
- "the endAck callback is called when consumed() is called");
1368
-
1369
- {
1370
- LOCK();
1371
- toConsume = -1;
1372
- }
1373
- feedChannel("");
1374
- EVENTUALLY(5,
1375
- result = getChannelState() == Channel::EOF_WAITING;
1376
- );
1377
- {
1378
- LOCK();
1379
- ensure_equals(endAcked, 0u);
1380
- }
1381
-
1382
- channelConsumed(0, false);
1383
- EVENTUALLY(5,
1384
- result = getChannelState() == Channel::EOF_REACHED;
1385
- );
1386
- {
1387
- LOCK();
1388
- ensure_equals(endAcked, 1u);
1389
- }
1390
- }
1391
-
1392
- TEST_METHOD(71) {
1393
- set_test_name("If the callback immediately consumes the EOF, "
1394
- "the endAck callback is called when the data callback returns");
1395
-
1396
- feedChannel("");
1397
- EVENTUALLY(5,
1398
- result = getChannelState() == Channel::EOF_REACHED;
1399
- );
1400
- {
1401
- LOCK();
1402
- ensure_equals(endAcked, 1u);
1403
- }
1404
- }
1405
-
1406
- TEST_METHOD(72) {
1407
- set_test_name("It no longer accepts further input");
1408
-
1409
- feedChannel("");
1410
- ensure(!channelIsAcceptingInput());
1411
- ensure(!channelMayAcceptInputLater());
1412
- }
1413
-
1414
-
1415
- /***** Upon being fed an error *****/
1416
-
1417
- TEST_METHOD(75) {
1418
- set_test_name("If the callback does not immediately consume the error, "
1419
- "the endAck callback is called when consumed() is called");
1420
-
1421
- {
1422
- LOCK();
1423
- toConsume = -1;
1424
- }
1425
- feedChannelError(EIO);
1426
- EVENTUALLY(5,
1427
- result = getChannelState() == Channel::EOF_WAITING;
1428
- );
1429
- {
1430
- LOCK();
1431
- ensure_equals(endAcked, 0u);
1432
- }
1433
-
1434
- channelConsumed(0, false);
1435
- EVENTUALLY(5,
1436
- result = getChannelState() == Channel::EOF_REACHED;
1437
- );
1438
- ensure_equals(getChannelErrcode(), EIO);
1439
- {
1440
- LOCK();
1441
- ensure_equals(endAcked, 1u);
1442
- }
1443
- }
1444
-
1445
- TEST_METHOD(76) {
1446
- set_test_name("If the callback immediately consumes the error, "
1447
- "the endAck callback is called when the data callback returns");
1448
-
1449
- feedChannelError(EIO);
1450
- EVENTUALLY(5,
1451
- result = getChannelState() == Channel::EOF_REACHED;
1452
- );
1453
- ensure_equals(getChannelErrcode(), EIO);
1454
- {
1455
- LOCK();
1456
- ensure_equals(endAcked, 1u);
1457
- }
1458
- }
1459
-
1460
- TEST_METHOD(77) {
1461
- set_test_name("It no longer accepts further input");
1462
-
1463
- feedChannelError(EIO);
1464
- ensure(!channelIsAcceptingInput());
1465
- ensure(!channelMayAcceptInputLater());
1466
- }
1467
- }