From 307444431a21bc7cb626da4472c82a287d554820 Mon Sep 17 00:00:00 2001 From: Nuwan Date: Sat, 29 May 2021 14:38:34 +0530 Subject: [PATCH] wip sepcs for musician latency badge --- admin/.gitignore | 1 + ruby/.gitignore | 1 + web/.gitignore | 1 + .../stores/LatencyStore.js.coffee | 2 +- web/app/controllers/api_users_controller.rb | 8 +-- .../controllers/api_users_controller_spec.rb | 7 +- web/spec/features/musician_hover_spec.rb | 71 +++++++++++++++++++ ...ncy_reponse.json => latency_response.json} | 0 websocket-gateway/.gitignore | 1 + websocket-gateway/Gemfile.lock | 1 + 10 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 web/spec/features/musician_hover_spec.rb rename web/spec/fixtures/{latency_reponse.json => latency_response.json} (100%) diff --git a/admin/.gitignore b/admin/.gitignore index d747d53e8..fae983383 100644 --- a/admin/.gitignore +++ b/admin/.gitignore @@ -22,3 +22,4 @@ artifacts BUILD_NUMBER # Gemfile.lock Gemfile.alt.lock +.byebug_history diff --git a/ruby/.gitignore b/ruby/.gitignore index 048a017ca..fe1f4d2c5 100644 --- a/ruby/.gitignore +++ b/ruby/.gitignore @@ -22,3 +22,4 @@ vendor *~ *.swp *.iml +.byebug_history diff --git a/web/.gitignore b/web/.gitignore index 585c62dfb..3dd570b24 100644 --- a/web/.gitignore +++ b/web/.gitignore @@ -42,3 +42,4 @@ public/assets public/uploads /log/*.out BUILD_NUMBER +.byebug_history diff --git a/web/app/assets/javascripts/react-components/stores/LatencyStore.js.coffee b/web/app/assets/javascripts/react-components/stores/LatencyStore.js.coffee index d5e6793fa..b4015f319 100644 --- a/web/app/assets/javascripts/react-components/stores/LatencyStore.js.coffee +++ b/web/app/assets/javascripts/react-components/stores/LatencyStore.js.coffee @@ -22,7 +22,7 @@ rest = new context.JK.Rest() rest.getLatencyToUsers({user_ids: user_ids}).done((response) => @onLoaded(response)).fail((jqXHR) => @onLatencyFail(jqXHR, user_ids)) onLoaded: (response) -> - #logger.debug("LatencyStore.onLoaded", response); + logger.debug("LatencyStore.onLoaded", response); @latencies.push(response) @changed() diff --git a/web/app/controllers/api_users_controller.rb b/web/app/controllers/api_users_controller.rb index 5d9ab713c..4b26d4530 100644 --- a/web/app/controllers/api_users_controller.rb +++ b/web/app/controllers/api_users_controller.rb @@ -939,8 +939,6 @@ class ApiUsersController < ApiController def get_latencies user_ids = params[:user_ids] - #query_str = user_ids.inject(""){|q, id| q.concat("id=#{id}&")} - #latency_url = "#{Rails.application.config.latency_data_host}/dev/user_latencies/#{current_user.id}?#{query_str}" latency_url = "#{Rails.application.config.latency_data_host}/dev/user_latencies" uri = URI(latency_url) begin @@ -956,9 +954,10 @@ class ApiUsersController < ApiController my_client_id: 'unknown', users: user_ids }.to_json - logger.debug(">>>>>>>>>>>>>>>>>>>>>>> before sending") + response = http.request(req) - logger.debug(">>>>>>>>>>>>>>>>>>>>>>> #{response.inspect}") + #debugger + if response.is_a?(Net::HTTPOK) || response.is_a?(Net::HTTPSuccess) render json: response.body, status: 200 else @@ -977,6 +976,7 @@ class ApiUsersController < ApiController render json: {}, status: 422 end rescue => exception + #debugger logger.debug("Latency exception: #{exception.message}") Bugsnag.notify(exception) do |report| report.severity = "error" diff --git a/web/spec/controllers/api_users_controller_spec.rb b/web/spec/controllers/api_users_controller_spec.rb index f019ea6c3..f1daba6a2 100644 --- a/web/spec/controllers/api_users_controller_spec.rb +++ b/web/spec/controllers/api_users_controller_spec.rb @@ -314,12 +314,13 @@ describe ApiUsersController, type: :controller do describe "get_latencies" do let(:user1) { FactoryGirl.create(:user) } let(:user2) { FactoryGirl.create(:user) } - let(:latency_data_uri) { /\/dev\/user_latencies\// } - let(:response_body) { File.open('./spec/fixtures/latency_reponse.json') } + let(:latency_data_uri) { /\S+\/dev\/user_latencies/ } + let(:response_body) { File.open('./spec/fixtures/latency_response.json') } it "fetch latency graph data" do - stub_request(:get, latency_data_uri) + stub_request(:post, latency_data_uri) .to_return( body: response_body, status: 200) + get :get_latencies, id: user.id, user_ids: [user1, user2].map(&:id).join(',') response.should be_success JSON.parse(response.body)['users'].size.should eq(2) diff --git a/web/spec/features/musician_hover_spec.rb b/web/spec/features/musician_hover_spec.rb new file mode 100644 index 000000000..e0c99ad5e --- /dev/null +++ b/web/spec/features/musician_hover_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' +require 'webmock/rspec' + +describe "Musician Hover", :js => true, :type => :feature, :capybara_feature => true do + let(:user1) { FactoryGirl.create(:user) } + let(:user2) { FactoryGirl.create(:user) } + + let(:latency_data_uri) { /\S+\/dev\/user_latencies/ } + + before(:all) do + WebMock.disable_net_connect!(allow_localhost: true) + end + + before(:each) do + fast_signin(user1, "/client") + wait_until_curtain_gone + end + + describe "Latency badge" do + + it "show FAILED" do + response_body = latency_response(user2, -3) #sessionUtils.LATENCY.FAILED: {description: "FAILED", style: "latency-failed", min: -3, max: -3} + stub_request(:post, latency_data_uri) + .to_return( body: response_body, status: 200) + + site_search(user2.first_name, expand: true) + find("#search-results a[user-id=\"#{user2.id}\"][hoveraction=\"musician\"]", text: user2.name).hover_intent + find('h3', text: user2.name) + find("#musician-latency-badge div.latency", text: 'FAILED') + end + end + + it "show GOOD" do + response_body = latency_response(user2, 40) #sessionUtils.LATENCY.GOOD : {description: "GOOD", style: "latency-good", min: 0.0, max: 40.0}, + stub_request(:post, latency_data_uri) + .to_return( body: response_body, status: 200) + + site_search(user2.first_name, expand: true) + find("#search-results a[user-id=\"#{user2.id}\"][hoveraction=\"musician\"]", text: user2.name).hover_intent + find('h3', text: user2.name) + find("#musician-latency-badge div.latency", text: 'GOOD') + end + + + def latency_response(user, latency) + { + "users": [ + { + "user_id": user.id, + "first_name": user.first_name, + "last_name": user.last_name, + "audio_latency": 4.0, + "audio_latency_unknown": false, + "ars": { + "internet_latency": latency, + "total_latency": latency + }, + "p2p": { + "internet_latency": latency, + "total_latency": latency + }, + "wifi": false + } + ], + "my_audio_latency": 4.0, + "my_audio_latency_unknown": false + }.to_json + end + +end + diff --git a/web/spec/fixtures/latency_reponse.json b/web/spec/fixtures/latency_response.json similarity index 100% rename from web/spec/fixtures/latency_reponse.json rename to web/spec/fixtures/latency_response.json diff --git a/websocket-gateway/.gitignore b/websocket-gateway/.gitignore index f2b32455d..bb21c2317 100644 --- a/websocket-gateway/.gitignore +++ b/websocket-gateway/.gitignore @@ -25,3 +25,4 @@ log/* target vendor BUILD_NUMBER +.byebug_history diff --git a/websocket-gateway/Gemfile.lock b/websocket-gateway/Gemfile.lock index fb4987b4f..cd6f896f0 100644 --- a/websocket-gateway/Gemfile.lock +++ b/websocket-gateway/Gemfile.lock @@ -578,6 +578,7 @@ DEPENDENCIES newrelic_rpm nokogiri (= 1.10.10) oj (= 3.1.3) + pg (= 0.17.1) postgres-copy postgres_ext protected_attributes