wip sepcs for musician latency badge

This commit is contained in:
Nuwan 2021-05-29 14:38:34 +05:30
parent 10908623a4
commit 307444431a
10 changed files with 85 additions and 8 deletions

1
admin/.gitignore vendored
View File

@ -22,3 +22,4 @@ artifacts
BUILD_NUMBER BUILD_NUMBER
# Gemfile.lock # Gemfile.lock
Gemfile.alt.lock Gemfile.alt.lock
.byebug_history

1
ruby/.gitignore vendored
View File

@ -22,3 +22,4 @@ vendor
*~ *~
*.swp *.swp
*.iml *.iml
.byebug_history

1
web/.gitignore vendored
View File

@ -42,3 +42,4 @@ public/assets
public/uploads public/uploads
/log/*.out /log/*.out
BUILD_NUMBER BUILD_NUMBER
.byebug_history

View File

@ -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)) rest.getLatencyToUsers({user_ids: user_ids}).done((response) => @onLoaded(response)).fail((jqXHR) => @onLatencyFail(jqXHR, user_ids))
onLoaded: (response) -> onLoaded: (response) ->
#logger.debug("LatencyStore.onLoaded", response); logger.debug("LatencyStore.onLoaded", response);
@latencies.push(response) @latencies.push(response)
@changed() @changed()

View File

@ -939,8 +939,6 @@ class ApiUsersController < ApiController
def get_latencies def get_latencies
user_ids = params[:user_ids] 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" latency_url = "#{Rails.application.config.latency_data_host}/dev/user_latencies"
uri = URI(latency_url) uri = URI(latency_url)
begin begin
@ -956,9 +954,10 @@ class ApiUsersController < ApiController
my_client_id: 'unknown', my_client_id: 'unknown',
users: user_ids users: user_ids
}.to_json }.to_json
logger.debug(">>>>>>>>>>>>>>>>>>>>>>> before sending")
response = http.request(req) response = http.request(req)
logger.debug(">>>>>>>>>>>>>>>>>>>>>>> #{response.inspect}") #debugger
if response.is_a?(Net::HTTPOK) || response.is_a?(Net::HTTPSuccess) if response.is_a?(Net::HTTPOK) || response.is_a?(Net::HTTPSuccess)
render json: response.body, status: 200 render json: response.body, status: 200
else else
@ -977,6 +976,7 @@ class ApiUsersController < ApiController
render json: {}, status: 422 render json: {}, status: 422
end end
rescue => exception rescue => exception
#debugger
logger.debug("Latency exception: #{exception.message}") logger.debug("Latency exception: #{exception.message}")
Bugsnag.notify(exception) do |report| Bugsnag.notify(exception) do |report|
report.severity = "error" report.severity = "error"

View File

@ -314,12 +314,13 @@ describe ApiUsersController, type: :controller do
describe "get_latencies" do describe "get_latencies" do
let(:user1) { FactoryGirl.create(:user) } let(:user1) { FactoryGirl.create(:user) }
let(:user2) { FactoryGirl.create(:user) } let(:user2) { FactoryGirl.create(:user) }
let(:latency_data_uri) { /\/dev\/user_latencies\// } let(:latency_data_uri) { /\S+\/dev\/user_latencies/ }
let(:response_body) { File.open('./spec/fixtures/latency_reponse.json') } let(:response_body) { File.open('./spec/fixtures/latency_response.json') }
it "fetch latency graph data" do 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) .to_return( body: response_body, status: 200)
get :get_latencies, id: user.id, user_ids: [user1, user2].map(&:id).join(',') get :get_latencies, id: user.id, user_ids: [user1, user2].map(&:id).join(',')
response.should be_success response.should be_success
JSON.parse(response.body)['users'].size.should eq(2) JSON.parse(response.body)['users'].size.should eq(2)

View File

@ -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

View File

@ -25,3 +25,4 @@ log/*
target target
vendor vendor
BUILD_NUMBER BUILD_NUMBER
.byebug_history

View File

@ -578,6 +578,7 @@ DEPENDENCIES
newrelic_rpm newrelic_rpm
nokogiri (= 1.10.10) nokogiri (= 1.10.10)
oj (= 3.1.3) oj (= 3.1.3)
pg (= 0.17.1)
postgres-copy postgres-copy
postgres_ext postgres_ext
protected_attributes protected_attributes