~ted/ubuntu-app-launch/jobs-systemd

« back to all changes in this revision

Viewing changes to tests/libual-cpp-test.cc

  • Committer: Ted Gould
  • Date: 2016-11-17 16:58:26 UTC
  • mfrom: (257.2.13 signal-instances)
  • Revision ID: ted@gould.cx-20161117165826-huy4oueyuea1bth0
Pulling through trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1575
1575
    }
1576
1576
};
1577
1577
 
1578
 
static void signal_increment(GDBusConnection* connection,
1579
 
                             const gchar* sender,
1580
 
                             const gchar* path,
1581
 
                             const gchar* interface,
1582
 
                             const gchar* signal,
1583
 
                             GVariant* params,
1584
 
                             gpointer user_data)
1585
 
{
1586
 
    guint* count = (guint*)user_data;
1587
 
    g_debug("Count incremented to: %d", *count + 1);
1588
 
    *count = *count + 1;
1589
 
}
1590
 
 
1591
1578
// DISABLED: Skipping these tests to not block on bug #1584849
1592
1579
TEST_F(LibUAL, DISABLED_PauseResume)
1593
1580
{
1629
1616
    /* Setup signal handling */
1630
1617
    guint paused_count = 0;
1631
1618
    guint resumed_count = 0;
1632
 
    guint paused_signal =
1633
 
        g_dbus_connection_signal_subscribe(bus, nullptr, "com.canonical.UbuntuAppLaunch", "ApplicationPaused", "/",
1634
 
                                           nullptr, G_DBUS_SIGNAL_FLAGS_NONE, signal_increment, &paused_count, nullptr);
1635
 
    guint resumed_signal = g_dbus_connection_signal_subscribe(
1636
 
        bus, nullptr, "com.canonical.UbuntuAppLaunch", "ApplicationResumed", "/", nullptr, G_DBUS_SIGNAL_FLAGS_NONE,
1637
 
        signal_increment, &resumed_count, nullptr);
 
1619
 
 
1620
    ubuntu::app_launch::Registry::appPaused(registry).connect(
 
1621
        [&paused_count](std::shared_ptr<ubuntu::app_launch::Application> app,
 
1622
                        std::shared_ptr<ubuntu::app_launch::Application::Instance> inst, std::vector<pid_t>& pids) {
 
1623
            g_debug("App paused: %s (%s)", std::string(app->appId()).c_str(),
 
1624
                    std::accumulate(pids.begin(), pids.end(), std::string{},
 
1625
                                    [](const std::string& accum, pid_t pid) {
 
1626
                                        return accum.empty() ? std::to_string(pid) : accum + ", " + std::to_string(pid);
 
1627
                                    })
 
1628
                        .c_str());
 
1629
            paused_count++;
 
1630
        });
 
1631
    ubuntu::app_launch::Registry::appResumed(registry).connect(
 
1632
        [&resumed_count](std::shared_ptr<ubuntu::app_launch::Application> app,
 
1633
                         std::shared_ptr<ubuntu::app_launch::Application::Instance> inst, std::vector<pid_t>& pids) {
 
1634
            g_debug("App resumed: %s (%s)", std::string(app->appId()).c_str(),
 
1635
                    std::accumulate(pids.begin(), pids.end(), std::string{},
 
1636
                                    [](const std::string& accum, pid_t pid) {
 
1637
                                        return accum.empty() ? std::to_string(pid) : accum + ", " + std::to_string(pid);
 
1638
                                    })
 
1639
                        .c_str());
 
1640
            resumed_count++;
 
1641
        });
1638
1642
 
1639
1643
    /* Get our app object */
1640
1644
    auto appid = ubuntu::app_launch::AppID::find(registry, "com.test.good_application_1.2.3");
1690
1694
    EXPECT_EQ("100", spew.oomScore());
1691
1695
 
1692
1696
    g_spawn_command_line_sync("rm -rf " CMAKE_BINARY_DIR "/libual-proc", NULL, NULL, NULL, NULL);
1693
 
 
1694
 
    g_dbus_connection_signal_unsubscribe(bus, paused_signal);
1695
 
    g_dbus_connection_signal_unsubscribe(bus, resumed_signal);
1696
1697
}
1697
1698
 
1698
1699
TEST_F(LibUAL, MultiPause)
1738
1739
    do
1739
1740
    {
1740
1741
        g_debug("Giving mocks a chance to start");
1741
 
        pause(200);
 
1742
        pause(20);
1742
1743
    } while (dbus_test_task_get_state(DBUS_TEST_TASK(cgmock2)) != DBUS_TEST_TASK_STATE_RUNNING &&
1743
1744
             dbus_test_task_get_state(DBUS_TEST_TASK(zgmock)) != DBUS_TEST_TASK_STATE_RUNNING);
1744
1745
 
 
1746
    /* Setup signal handling */
 
1747
    guint paused_count = 0;
 
1748
    guint resumed_count = 0;
 
1749
 
 
1750
    ubuntu::app_launch::Registry::appPaused(registry).connect(
 
1751
        [&paused_count](std::shared_ptr<ubuntu::app_launch::Application> app,
 
1752
                        std::shared_ptr<ubuntu::app_launch::Application::Instance> inst, std::vector<pid_t>& pids) {
 
1753
            g_debug("App paused: %s (%s)", std::string(app->appId()).c_str(),
 
1754
                    std::accumulate(pids.begin(), pids.end(), std::string{},
 
1755
                                    [](const std::string& accum, pid_t pid) {
 
1756
                                        return accum.empty() ? std::to_string(pid) : accum + ", " + std::to_string(pid);
 
1757
                                    })
 
1758
                        .c_str());
 
1759
            paused_count++;
 
1760
        });
 
1761
    ubuntu::app_launch::Registry::appResumed(registry).connect(
 
1762
        [&resumed_count](std::shared_ptr<ubuntu::app_launch::Application> app,
 
1763
                         std::shared_ptr<ubuntu::app_launch::Application::Instance> inst, std::vector<pid_t>& pids) {
 
1764
            g_debug("App resumed: %s (%s)", std::string(app->appId()).c_str(),
 
1765
                    std::accumulate(pids.begin(), pids.end(), std::string{},
 
1766
                                    [](const std::string& accum, pid_t pid) {
 
1767
                                        return accum.empty() ? std::to_string(pid) : accum + ", " + std::to_string(pid);
 
1768
                                    })
 
1769
                        .c_str());
 
1770
            resumed_count++;
 
1771
        });
 
1772
 
1745
1773
    /* Get our app object */
1746
1774
    auto appid = ubuntu::app_launch::AppID::find(registry, "com.test.good_application_1.2.3");
1747
1775
    auto app = ubuntu::app_launch::Application::create(appid, registry);
1757
1785
    /* Pause the app */
1758
1786
    instance->pause();
1759
1787
 
 
1788
    EXPECT_EVENTUALLY_EQ(1, paused_count);
 
1789
 
1760
1790
    std::for_each(spews.begin(), spews.end(), [](SpewMaster& spew) { spew.reset(); });
1761
1791
    pause(50);
1762
1792
 
1767
1797
    /* Now Resume the App */
1768
1798
    instance->resume();
1769
1799
 
 
1800
    EXPECT_EVENTUALLY_EQ(1, resumed_count);
 
1801
 
1770
1802
    pause(50);
1771
1803
 
1772
1804
    EXPECT_NE(0, std::accumulate(spews.begin(), spews.end(), int{0},
1775
1807
    /* Pause the app */
1776
1808
    instance->pause();
1777
1809
 
 
1810
    EXPECT_EVENTUALLY_EQ(2, paused_count);
 
1811
 
1778
1812
    std::for_each(spews.begin(), spews.end(), [](SpewMaster& spew) { spew.reset(); });
1779
1813
    pause(50);
1780
1814
 
1785
1819
    /* Now Resume the App */
1786
1820
    instance->resume();
1787
1821
 
 
1822
    EXPECT_EVENTUALLY_EQ(2, resumed_count);
 
1823
 
1788
1824
    pause(50);
1789
1825
 
1790
1826
    EXPECT_NE(0, std::accumulate(spews.begin(), spews.end(), int{0},