• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-core / 2213

10 Apr 2024 11:21PM UTC coverage: 91.792% (-0.8%) from 92.623%
2213

push

Evergreen

web-flow
Add missing availability checks for SecCopyErrorMessageString (#7577)

This requires iOS 11.3 and we currently target iOS 11.

94842 of 175770 branches covered (53.96%)

7 of 22 new or added lines in 2 files covered. (31.82%)

1861 existing lines in 82 files now uncovered.

242866 of 264583 relevant lines covered (91.79%)

5593111.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.73
/test/object-store/sync/session/wait_for_completion.cpp
1
////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2017 Realm Inc.
4
//
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
//
17
////////////////////////////////////////////////////////////////////////////
18

19
#include <util/event_loop.hpp>
20
#include <util/test_file.hpp>
21
#include <util/test_utils.hpp>
22
#include <util/sync/session_util.hpp>
23

24
#include <realm/util/scope_exit.hpp>
25

26
#include <catch2/catch_all.hpp>
27

28
using namespace realm;
29
using namespace realm::util;
30

31
TEST_CASE("SyncSession: wait_for_download_completion() API", "[sync][pbs][session][completion]") {
6✔
32
    if (!EventLoop::has_implementation())
6✔
33
        return;
×
34

3✔
35
    TestSyncManager tsm({}, {false});
6✔
36
    auto& server = tsm.sync_server();
6✔
37
    auto sync_manager = tsm.sync_manager();
6✔
38
    std::atomic<bool> handler_called(false);
6✔
39

3✔
40
    SECTION("works properly when called after the session is bound") {
6✔
41
        server.start();
2✔
42
        auto user = tsm.fake_user();
2✔
43
        auto session = sync_session(user, "/async-wait-download-1", [](auto, auto) {});
1✔
44
        EventLoop::main().run_until([&] {
3✔
45
            return sessions_are_active(*session);
3✔
46
        });
3✔
47
        // Register the download-completion notification
1✔
48
        session->wait_for_download_completion([&](auto) {
2✔
49
            handler_called = true;
2✔
50
        });
2✔
51
        EventLoop::main().run_until([&] {
33,893✔
52
            return handler_called == true;
33,893✔
53
        });
33,893✔
54
    }
2✔
55

3✔
56
    SECTION("works properly when called on a logged-out session") {
6✔
57
        server.start();
2✔
58
        auto user = tsm.fake_user();
2✔
59
        auto session = sync_session(user, "/user-async-wait-download-3", [](auto, auto) {});
1✔
60
        EventLoop::main().run_until([&] {
3✔
61
            return sessions_are_active(*session);
3✔
62
        });
3✔
63
        // Log the user out, and wait for the sessions to log out.
1✔
64
        user->log_out();
2✔
65
        EventLoop::main().run_until([&] {
3✔
66
            return sessions_are_inactive(*session);
3✔
67
        });
3✔
68
        // Register the download-completion notification
1✔
69
        session->wait_for_download_completion([&](auto) {
2✔
70
            handler_called = true;
2✔
71
        });
2✔
72
        spin_runloop();
2✔
73
        REQUIRE(handler_called == false);
2!
74
        // Log the user back in
1✔
75
        user->log_in();
2✔
76
        EventLoop::main().run_until([&] {
3✔
77
            return sessions_are_active(*session);
3✔
78
        });
3✔
79
        // Now, wait for the completion handler to be called.
1✔
80
        EventLoop::main().run_until([&] {
11,695✔
81
            return handler_called == true;
11,695✔
82
        });
11,695✔
83
    }
2✔
84

3✔
85
    SECTION("aborts properly when queued and the session errors out") {
6✔
86
        auto user = tsm.fake_user();
2✔
87
        std::atomic<int> error_count(0);
2✔
88
        std::shared_ptr<SyncSession> session = sync_session(user, "/async-wait-download-4", [&](auto, auto) {
2✔
89
            ++error_count;
2✔
90
        });
2✔
91
        Status err_status(ErrorCodes::SyncProtocolInvariantFailed, "Not a real error message");
2✔
92
        // Register the download-completion notification
1✔
93
        session->wait_for_download_completion([&](Status status) {
2✔
94
            REQUIRE(status == err_status);
2!
95
            handler_called = true;
2✔
96
        });
2✔
97
        REQUIRE(handler_called == false);
2!
98
        // Now trigger an error
1✔
99
        sync::SessionErrorInfo err{err_status, sync::IsFatal{true}};
2✔
100
        err.server_requests_action = sync::ProtocolErrorInfo::Action::ProtocolViolation;
2✔
101
        SyncSession::OnlyForTesting::handle_error(*session, std::move(err));
2✔
102
        EventLoop::main().run_until([&] {
3✔
103
            return error_count > 0;
3✔
104
        });
3✔
105
        REQUIRE(handler_called == true);
2!
106
    }
2✔
107
}
6✔
108

109
TEST_CASE("SyncSession: wait_for_upload_completion() API", "[sync][pbs][session][completion]") {
4✔
110
    if (!EventLoop::has_implementation())
4✔
UNCOV
111
        return;
×
112

2✔
113
    TestSyncManager tsm({}, {false});
4✔
114
    auto& server = tsm.sync_server();
4✔
115
    auto sync_manager = tsm.sync_manager();
4✔
116
    std::atomic<bool> handler_called(false);
4✔
117

2✔
118
    SECTION("works properly when called after the session is bound") {
4✔
119
        server.start();
2✔
120
        auto user = tsm.fake_user();
2✔
121
        auto session = sync_session(user, "/async-wait-upload-1", [](auto, auto) {});
1✔
122
        EventLoop::main().run_until([&] {
3✔
123
            return sessions_are_active(*session);
3✔
124
        });
3✔
125
        // Register the upload-completion notification
1✔
126
        session->wait_for_upload_completion([&](auto) {
2✔
127
            handler_called = true;
2✔
128
        });
2✔
129
        EventLoop::main().run_until([&] {
191✔
130
            return handler_called == true;
191✔
131
        });
191✔
132
    }
2✔
133

2✔
134
    SECTION("works properly when called on a logged-out session") {
4✔
135
        server.start();
2✔
136
        auto user = tsm.fake_user();
2✔
137
        auto session = sync_session(user, "/user-async-wait-upload-3", [](auto, auto) {});
1✔
138
        EventLoop::main().run_until([&] {
3✔
139
            return sessions_are_active(*session);
3✔
140
        });
3✔
141
        // Log the user out, and wait for the sessions to log out.
1✔
142
        user->log_out();
2✔
143
        EventLoop::main().run_until([&] {
3✔
144
            return sessions_are_inactive(*session);
3✔
145
        });
3✔
146
        // Register the upload-completion notification
1✔
147
        session->wait_for_upload_completion([&](auto) {
2✔
148
            handler_called = true;
2✔
149
        });
2✔
150
        spin_runloop();
2✔
151
        REQUIRE(handler_called == false);
2!
152
        // Log the user back in
1✔
153
        user->log_in();
2✔
154
        EventLoop::main().run_until([&] {
3✔
155
            return sessions_are_active(*session);
3✔
156
        });
3✔
157
        // Now, wait for the completion handler to be called.
1✔
158
        EventLoop::main().run_until([&] {
296✔
159
            return handler_called == true;
296✔
160
        });
296✔
161
    }
2✔
162

2✔
163
    // FIXME: There seems to be a race condition here where the upload completion handler
2✔
164
    // FIXME: isn't actually called with the appropriate error, only the error handler is
2✔
165
    //    SECTION("aborts properly when queued and the session errors out") {
2✔
166
    //        using ProtocolError = realm::sync::ProtocolError;
2✔
167
    //        auto user = SyncManager::shared().get_user("user-async-wait-upload-4",
2✔
168
    //        ENCODE_FAKE_JWT("not_a_real_token"), ENCODE_FAKE_JWT("not_a_real_token"),
2✔
169
    //        dummy_device_id); std::atomic<int> error_count(0); std::shared_ptr<SyncSession> session =
2✔
170
    //        sync_session(user, "/async-wait-upload-4",
2✔
171
    //                                                            [&](auto e) {
2✔
172
    //            ++error_count;
2✔
173
    //        });
2✔
174
    //        std::error_code code = std::error_code{static_cast<int>(ProtocolError::bad_syntax),
2✔
175
    //        realm::sync::protocol_error_category()};
2✔
176
    //        // Register the upload-completion notification
2✔
177
    //        session->wait_for_upload_completion([&](std::error_code error) {
2✔
178
    //            CHECK(error == code);
2✔
179
    //            handler_called = true;
2✔
180
    //        });
2✔
181
    //        REQUIRE(handler_called == false);
2✔
182
    //        // Now trigger an error
2✔
183
    //        SyncSession::OnlyForTesting::handle_error(*session, {code, "Not a real error message", false});
2✔
184
    //        EventLoop::main().run_until([&] {
2✔
185
    //            return error_count > 0 && handler_called;
2✔
186
    //        });
2✔
187
    //        REQUIRE(handler_called == true);
2✔
188
    //    }
2✔
189
}
4✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc