You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

request_timer_struct_spec.rb 3.4 kB

12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. require 'spec_helper'
  2. require 'rack-mini-profiler'
  3. describe Rack::MiniProfiler::RequestTimerStruct do
  4. def new_page
  5. Rack::MiniProfiler::PageTimerStruct.new({})
  6. end
  7. before do
  8. @name = 'cool request'
  9. @request = Rack::MiniProfiler::RequestTimerStruct.createRoot(@name, new_page)
  10. end
  11. it 'sets IsRoot to true' do
  12. @request['IsRoot'].should be_true
  13. end
  14. it 'has an Id' do
  15. @request['Id'].should_not be_nil
  16. end
  17. it 'has a Root' do
  18. @request['Name'].should == @name
  19. end
  20. it 'begins with a children duration of 0' do
  21. @request.children_duration.should == 0
  22. end
  23. it 'has a false HasChildren attribute' do
  24. @request['HasChildren'].should be_false
  25. end
  26. it 'has an empty Children attribute' do
  27. @request['Children'].should be_empty
  28. end
  29. it 'has a depth of 0' do
  30. @request['Depth'].should == 0
  31. end
  32. it 'has a false HasSqlTimings attribute' do
  33. @request['HasSqlTimings'].should be_false
  34. end
  35. it 'has no sql timings at first' do
  36. @request['SqlTimings'].should be_empty
  37. end
  38. it 'has a 0 for SqlTimingsDurationMilliseconds' do
  39. @request['SqlTimingsDurationMilliseconds'].should == 0
  40. end
  41. describe 'add SQL' do
  42. before do
  43. @page = new_page
  44. @request.add_sql("SELECT 1 FROM users", 77, @page)
  45. end
  46. it 'has a true HasSqlTimings attribute' do
  47. @request['HasSqlTimings'].should be_true
  48. end
  49. it 'has the SqlTiming object' do
  50. @request['SqlTimings'].should_not be_empty
  51. end
  52. it 'has a child with the ParentTimingId of the request' do
  53. @request['SqlTimings'][0]['ParentTimingId'].should == @request['Id']
  54. end
  55. it 'increases SqlTimingsDurationMilliseconds' do
  56. @request['SqlTimingsDurationMilliseconds'].should == 77
  57. end
  58. it "increases the page's " do
  59. @page['DurationMillisecondsInSql'].should == 77
  60. end
  61. end
  62. describe 'record time' do
  63. describe 'add children' do
  64. before do
  65. @child = @request.add_child('child')
  66. @child.record_time(1111)
  67. end
  68. it 'has a IsRoot value of false' do
  69. @child['IsRoot'].should be_false
  70. end
  71. it 'has a true HasChildren attribute' do
  72. @request['HasChildren'].should be_true
  73. end
  74. it 'has the child in the Children attribute' do
  75. @request['Children'].should == [@child]
  76. end
  77. it 'assigns its Id to the child' do
  78. @child['ParentTimingId'].should == @request['Id']
  79. end
  80. it 'assigns a depth of 1 to the child' do
  81. @child['Depth'].should == 1
  82. end
  83. it 'increases the children duration' do
  84. @request.children_duration.should == 1111
  85. end
  86. it 'marks short timings as trivial' do
  87. @request.record_time(1)
  88. @request['IsTrivial'].should be_true
  89. end
  90. describe 'record time on parent' do
  91. before do
  92. @request.record_time(1234)
  93. end
  94. it "is not a trivial query" do
  95. @request['IsTrivial'].should be_false
  96. end
  97. it 'has stores the recorded time in DurationMilliseconds' do
  98. @request['DurationMilliseconds'].should == 1234
  99. end
  100. it 'calculates DurationWithoutChildrenMilliseconds without the children timings' do
  101. @request['DurationWithoutChildrenMilliseconds'].should == 123
  102. end
  103. end
  104. end
  105. end
  106. end

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...