Musician hover latency badge
show latency score badge on hover over musician. fetches data from new resolve latency data API
This commit is contained in:
parent
11d8af22bb
commit
c7547405f8
|
|
@ -190,17 +190,21 @@
|
|||
var latency;
|
||||
$(document).one('user_latency_update', function(e, latencyResp){
|
||||
latency = latencyResp['users'][0];
|
||||
logger.debug("bindUserLatencyUpdate", latency)
|
||||
if(latency['user_id'] === userId){
|
||||
showLatencyBadge(latency)
|
||||
//logger.debug("bindUserLatencyUpdate", latency)
|
||||
if(latency != undefined){
|
||||
if(latency['user_id'] === userId){
|
||||
showLatencyBadge(latency)
|
||||
}
|
||||
}else{
|
||||
showUnknownLatencyBadge(userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function bindUserLatencyFail(){
|
||||
$(document).one('user_latency_fail', function(e, failedUserIds){
|
||||
logger.debug("bindUserLatencyFail", failedUserIds)
|
||||
if(_.contains(failedUserIds, userId) || failedUserIds === userId){
|
||||
//logger.debug("bindUserLatencyFail", failedUserIds)
|
||||
if(_.contains(failedUserIds, userId)){
|
||||
showFailedLatencyBadge(userId)
|
||||
}
|
||||
});
|
||||
|
|
@ -223,11 +227,23 @@
|
|||
"audio_latency": 0,
|
||||
"ars": {
|
||||
"internet_latency": 0,
|
||||
"total_latency": -3
|
||||
"total_latency": -3.0
|
||||
}
|
||||
};
|
||||
showLatencyBadge(failedLatency);
|
||||
}
|
||||
|
||||
function showUnknownLatencyBadge(userId){
|
||||
var unknownLatency = {
|
||||
"user_id": userId,
|
||||
"audio_latency": 0,
|
||||
"ars": {
|
||||
"internet_latency": 0,
|
||||
"total_latency": -2
|
||||
}
|
||||
};
|
||||
showLatencyBadge(unknownLatency);
|
||||
}
|
||||
|
||||
function unbindUserLatencyUpdate(){
|
||||
$(document).off('user_latency_update');
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ rest = new context.JK.Rest()
|
|||
@trigger(@latencies)
|
||||
|
||||
onResolve: (user_ids) ->
|
||||
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) ->
|
||||
logger.debug("LatencyStore.onLoaded", response);
|
||||
|
|
|
|||
|
|
@ -101,18 +101,24 @@
|
|||
iconName = 'purple';
|
||||
description = 'me';
|
||||
}
|
||||
else if (!full_score) {
|
||||
latencyDescription = LATENCY.UNKNOWN.description;
|
||||
latencyStyle = LATENCY.UNKNOWN.style;
|
||||
iconName = 'purple';
|
||||
description = 'missing';
|
||||
}
|
||||
else if (full_score <= LATENCY.FAILED.max) {
|
||||
latencyDescription = LATENCY.FAILED.description;
|
||||
latencyStyle = LATENCY.FAILED.style;
|
||||
iconName = 'gray';
|
||||
description = 'failed';
|
||||
}
|
||||
// else if (!full_score) {
|
||||
// latencyDescription = LATENCY.UNKNOWN.description;
|
||||
// latencyStyle = LATENCY.UNKNOWN.style;
|
||||
// iconName = 'purple';
|
||||
// description = 'missing';
|
||||
// }
|
||||
else if (!full_score || full_score <= LATENCY.UNKNOWN.max) {
|
||||
latencyDescription = LATENCY.UNKNOWN.description;
|
||||
latencyStyle = LATENCY.UNKNOWN.style;
|
||||
iconName = 'purple';
|
||||
description = 'missing';
|
||||
}
|
||||
else if (full_score <= LATENCY.GOOD.max) {
|
||||
latencyDescription = LATENCY.GOOD.description;
|
||||
latencyStyle = LATENCY.GOOD.style;
|
||||
|
|
@ -131,7 +137,7 @@
|
|||
iconName = 'red';
|
||||
description = 'poor';
|
||||
}
|
||||
else {
|
||||
else if (full_score > LATENCY.UNACCEPTABLE.min) {
|
||||
latencyStyle = LATENCY.UNACCEPTABLE.style;
|
||||
latencyDescription = LATENCY.UNACCEPTABLE.description;
|
||||
iconName = 'blue';
|
||||
|
|
|
|||
|
|
@ -937,7 +937,6 @@ class ApiUsersController < ApiController
|
|||
|
||||
#fetch latency information from latency-graph serverless
|
||||
def get_latencies
|
||||
|
||||
user_ids = params[:user_ids]
|
||||
latency_url = "#{Rails.application.config.latency_data_host}/dev/user_latencies"
|
||||
uri = URI(latency_url)
|
||||
|
|
@ -973,7 +972,7 @@ class ApiUsersController < ApiController
|
|||
body: response.body,
|
||||
})
|
||||
end
|
||||
render json: {}, status: 422
|
||||
render json: { user_ids: params[:user_ids] }, status: 422
|
||||
end
|
||||
rescue => exception
|
||||
#debugger
|
||||
|
|
@ -987,7 +986,7 @@ class ApiUsersController < ApiController
|
|||
url: latency_url,
|
||||
})
|
||||
end
|
||||
render json: {}, status: 500
|
||||
render json: { user_ids: params[:user_ids] }, status: 500
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ tests=(
|
|||
"spec/features/affiliate_program_spec.rb"
|
||||
"spec/features/affiliate_visit_tracking_spec.rb"
|
||||
"spec/features/affiliate_referral_spec.rb"
|
||||
"spec/features/musician_hover_spec_1.rb"
|
||||
"spec/features/musician_hover_spec_2.rb"
|
||||
"spec/controllers/api_affiliate_controller_spec.rb"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,137 +0,0 @@
|
|||
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 do
|
||||
#Capybara.javascript_driver = :capybara_webmock
|
||||
#Capybara.current_driver = Capybara.javascript_driver
|
||||
Capybara.default_max_wait_time = 30 # these tests are SLOOOOOW
|
||||
WebMock.disable_net_connect!(allow_localhost: true)
|
||||
end
|
||||
|
||||
after do
|
||||
#Capybara.use_default_driver
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
fast_signin(user1, "/client")
|
||||
wait_until_curtain_gone
|
||||
end
|
||||
|
||||
|
||||
describe "Latency badge" do
|
||||
|
||||
xit "show FAILED", focus: true 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)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.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", text: 'FAILED')
|
||||
#screenshot_and_save_page
|
||||
end
|
||||
|
||||
it "show POOR", focus: true do
|
||||
response_body = latency_response(user2, 71.0) #sessionUtils.LATENCY.POOR : {description: "POOR", style: "latency-poor", min: 70.0, max: 100},
|
||||
stub_request(:post, latency_data_uri)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.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: 'POOR')
|
||||
|
||||
end
|
||||
|
||||
it "show GOOD", focus: true do
|
||||
response_body = latency_response(user2, 1.0) #sessionUtils.LATENCY.GOOD : {description: "GOOD", style: "latency-good", min: 0.0, max: 40.0},
|
||||
stub_request(:post, latency_data_uri)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.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
|
||||
|
||||
it "show FAIR", focus: true do
|
||||
response_body = latency_response(user2, 41.0) #sessionUtils.LATENCY.FAIR : {description: "FAIR", style: "latency-fair", min: 40.0, max: 70.0},
|
||||
stub_request(:post, latency_data_uri)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.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: 'FAIR')
|
||||
|
||||
end
|
||||
|
||||
|
||||
it "show UNACCEPTABLE", focus: true do
|
||||
response_body = latency_response(user2, 101.0) #sessionUtils.LATENCY.UNACCEPTABLE : {description: "UNACCEPTABLE", style: "latency-unacceptable", min: 100.0, max: 10000000},
|
||||
stub_request(:post, latency_data_uri)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.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: 'UNACCEPTABLE')
|
||||
|
||||
end
|
||||
|
||||
it "show UNKNOWN", focus: true do
|
||||
response_body = latency_response(user2, nil) #sessionUtils.LATENCY.UNKNOWN: {description: "UNKNOWN", style: "latency-unknown", min: -2, max: -2}
|
||||
stub_request(:post, latency_data_uri)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.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: 'UNKNOWN')
|
||||
|
||||
end
|
||||
|
||||
def latency_response(user, latency)
|
||||
resp = {
|
||||
"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
|
||||
}
|
||||
#resp[:users][0][:ars][:total_latency] = latency unless latency.nil?
|
||||
resp.to_json
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
require 'spec_helper'
|
||||
require 'webmock/rspec'
|
||||
|
||||
#NOTE: The rest of the tests related to musician latency badge are in
|
||||
#musician_hover_spec_2.rb file. For some uncertain issue getting all these
|
||||
#tests in a single file doesn't work because some of them fail without a reason.
|
||||
#Probably because of webmock behaving wiredly.
|
||||
|
||||
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 do
|
||||
Capybara.default_max_wait_time = 30 # these tests are SLOOOOOW
|
||||
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 ME (same user)" do
|
||||
response_body = mock_latency_response(user1, 1.0) #sessionUtils.LATENCY.UNKNOWN: {description: "UNKNOWN", style: "latency-unknown", min: -2, max: -2}
|
||||
stub_request(:post, latency_data_uri)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.to_return( body: response_body, status: 200)
|
||||
|
||||
site_search(user1.first_name, expand: true)
|
||||
find("#search-results a[user-id=\"#{user1.id}\"][hoveraction=\"musician\"]", text: user1.name).hover_intent
|
||||
find('h3', text: user1.name)
|
||||
find("#musician-latency-badge div.latency", text: 'ME')
|
||||
end
|
||||
|
||||
it "show FAILED" do
|
||||
stub_request(:post, latency_data_uri)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.to_raise("some error")
|
||||
|
||||
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", text: 'FAILED')
|
||||
end
|
||||
|
||||
it "show UNKNOWN" do
|
||||
response_body = mock_latency_response(user2, nil) #sessionUtils.LATENCY.UNKNOWN: {description: "UNKNOWN", style: "latency-unknown", min: -2, max: -2}
|
||||
stub_request(:post, latency_data_uri)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.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: 'UNKNOWN')
|
||||
end
|
||||
|
||||
it "show GOOD" do
|
||||
response_body = mock_latency_response(user2, 1.0) #sessionUtils.LATENCY.GOOD : {description: "GOOD", style: "latency-good", min: 0.0, max: 40.0},
|
||||
stub_request(:post, latency_data_uri)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.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
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
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 do
|
||||
Capybara.default_max_wait_time = 30 # these tests are SLOOOOOW
|
||||
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 POOR" do
|
||||
response_body = mock_latency_response(user2, 71.0) #sessionUtils.LATENCY.POOR : {description: "POOR", style: "latency-poor", min: 70.0, max: 100},
|
||||
stub_request(:post, latency_data_uri)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.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: 'POOR')
|
||||
end
|
||||
|
||||
it "show FAIR" do
|
||||
response_body = mock_latency_response(user2, 41.0) #sessionUtils.LATENCY.FAIR : {description: "FAIR", style: "latency-fair", min: 40.0, max: 70.0},
|
||||
stub_request(:post, latency_data_uri)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.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: 'FAIR')
|
||||
end
|
||||
|
||||
it "show UNACCEPTABLE", focus: true do
|
||||
response_body = mock_latency_response(user2, 101.0) #sessionUtils.LATENCY.UNACCEPTABLE : {description: "UNACCEPTABLE", style: "latency-unacceptable", min: 100.0, max: 10000000},
|
||||
stub_request(:post, latency_data_uri)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.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: 'UNACCEPTABLE')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -795,4 +795,37 @@ end
|
|||
def nav_profile_history(user)
|
||||
visit Nav.profile(user)
|
||||
find('#history-link').trigger(:click)
|
||||
end
|
||||
|
||||
def mock_latency_response(user, latency)
|
||||
resp = nil
|
||||
if latency
|
||||
resp = {
|
||||
"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
|
||||
}
|
||||
else
|
||||
resp = {
|
||||
"users": []
|
||||
}
|
||||
end
|
||||
return resp.to_json
|
||||
end
|
||||
Loading…
Reference in New Issue