示例#1
0
def test_active_server_changes_if_playlist_not_modified_for_a_while(monkeypatch):
	PATH = '/path'
	SERVERS = ['http://server1', 'http://server2']
	paths = {PATH: SERVERS}
	b = Balancer()
	b.update(paths)

	now = datetime.datetime.now()

	assert [SERVERS[0]] == [s.server for s in b.actives]
	b.notify_modified()

	# 20 seconds later and playlist has not changed
	monkeypatch.setattr(b, '_now', lambda: now + datetime.timedelta(seconds=20))
	assert [SERVERS[1]] == [s.server for s in b.actives]

	# more 20 seconds later but backup is being updated
	monkeypatch.setattr(b, '_now', lambda: now + datetime.timedelta(seconds=40))
	b.notify_modified()
	assert [SERVERS[1]] == [s.server for s in b.actives]
def test_active_server_changes_if_playlist_not_modified_for_a_while(
        monkeypatch):
    PATH = '/path'
    SERVERS = ['http://server1', 'http://server2']
    paths = {PATH: SERVERS}
    b = Balancer()
    b.update(paths)

    now = datetime.datetime.now()

    assert [SERVERS[0]] == [s.server for s in b.actives]
    b.notify_modified()

    # 20 seconds later and playlist has not changed
    monkeypatch.setattr(b, '_now',
                        lambda: now + datetime.timedelta(seconds=20))
    assert [SERVERS[1]] == [s.server for s in b.actives]

    # more 20 seconds later but backup is being updated
    monkeypatch.setattr(b, '_now',
                        lambda: now + datetime.timedelta(seconds=40))
    b.notify_modified()
    assert [SERVERS[1]] == [s.server for s in b.actives]
def test_consume_from_balancer_should_not_report_content_modified_if_there_are_no_changes(tmpdir):
    server = Server(M3U8_HOST, M3U8_PORT)
    playlist = 'low'
    uri = '/low.m3u8'
    playlists = {'streams': {playlist: {'input-path': uri, 'servers': [server]}}}

    b = Balancer()
    b.update(get_servers(playlists))
    hlsclient.consumer.consume_from_balancer(b, playlists, str(tmpdir))

    modified = []
    b.notify_modified = lambda: modified.append("MODIFIED")
    hlsclient.consumer.consume_from_balancer(b, playlists, str(tmpdir))
    assert modified == []
def test_consume_from_balancer_should_report_content_modified(tmpdir):
    server = Server(M3U8_HOST, M3U8_PORT)
    playlist = 'low'
    uri = '/low.m3u8'
    playlists = {'streams': {playlist: {'input-path': uri, 'servers': [server]}}}

    modified = []
    b = Balancer()
    b.update(get_servers(playlists))
    b.notify_modified = lambda: modified.append("MODIFIED")
    hlsclient.consumer.consume_from_balancer(b, playlists, str(tmpdir))
    assert modified == ["MODIFIED"]

    expected_created = ['low.m3u8', 'low1.ts', 'low2.ts']
    resources_created = os.listdir(str(tmpdir))
    assert sorted(expected_created) == sorted(resources_created)
    for filename in resources_created:
        assert stat.S_IMODE(os.stat(str(tmpdir.join(filename))).st_mode) == 0644