File: Isolatedprocess_test.cpp

package info (click to toggle)
megacmd 2.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 32,592 kB
  • sloc: cpp: 326,437; ansic: 34,524; python: 4,630; java: 3,965; sh: 2,869; objc: 2,459; makefile: 197; xml: 113
file content (81 lines) | stat: -rw-r--r-- 2,652 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// none relevant small groups tests not worth of putting to its own test files
// are put here

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "mega/gfx/isolatedprocess.h"
#include "mega/scoped_timer.h"

#include <chrono>
#include <vector>

using mega::LocalPath;
using mega::ScopedSteadyTimer;
using std::chrono::seconds;
using Params = mega::GfxIsolatedProcess::Params;

TEST(Isolatedprocess, CancelableSleeperCanBecancelledInNoTime)
{
    ScopedSteadyTimer timer;

    mega::CancellableSleeper sleeper;
    std::thread t ([&sleeper](){
        sleeper.sleep(seconds(60)); // long enough
    });

    sleeper.cancel();

    if (t.joinable()) t.join();

    // cancel should be done immediately, but we don't want a
    // too short number that the result could be affected by disturbance.
    ASSERT_TRUE(timer.passedTime() < seconds(10));
}

//
// Test hellobeater can be shutdown quickly
//
TEST(Isolatedprocess, GfxWorkerHelloBeaterCanGracefullyShutdownInNoTime)
{
    ScopedSteadyTimer timer;
    {
        mega::HelloBeater beater(seconds(60), "__"); //long enough
    }
    // cancel should be done immediately, but we don't want a
    // too short number that the result could be affected by disturbance.
    ASSERT_TRUE(timer.passedTime() < seconds(10));
}

TEST(Isolatedprocess, ParamsConstructedWithDefaultAsExpected)
{
    const std::string exec{"the/path is/exe"};
    const std::string expectedExec{LocalPath::fromAbsolutePath(exec).toPath(false)};

    Params params{"endpoint", exec};
    ASSERT_THAT(params.toArgs(), testing::ElementsAre(expectedExec, "-n=endpoint", "-l=60"));
}

TEST(Isolatedprocess, ParamsConstructedWithExtraParametersAsExpected)
{
    const std::string exec{"the/path is/exe"};
    const std::string expectedExec{LocalPath::fromAbsolutePath(exec).toPath(false)};
    const auto rawArgs = std::vector<std::string>{"-t=10", "-d=the/path is/log"};

    Params params{"endpoint", exec, seconds{20}, rawArgs};
    ASSERT_THAT(
        params.toArgs(),
        testing::ElementsAre(expectedExec, "-n=endpoint", "-l=20", "-t=10", "-d=the/path is/log"));
}

// Duplicate parameters are also retained.
TEST(Isolatedprocess, ParamsConstructedWithDuplidatedExtraParametersAreKeptAsExpected)
{
    const std::string exec{"the/path is/exe"};
    const std::string expectedExec{LocalPath::fromAbsolutePath(exec).toPath(false)};
    const auto rawArgs = std::vector<std::string>{"-n=anotherEndplint", "-l=20"};

    Params params{"endpoint", exec, seconds{20}, rawArgs};
    ASSERT_THAT(
        params.toArgs(),
        testing::ElementsAre(expectedExec, "-n=endpoint", "-l=20", "-n=anotherEndplint", "-l=20"));
}