Repository navigation
Expand file tree
/
Copy pathtest_daemon_upgrade_state.cpp
More file actions
528 lines (447 loc) · 22.1 KB
/
Copy pathtest_daemon_upgrade_state.cpp
File metadata and controls
528 lines (447 loc) · 22.1 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
// -----------------------------------------------------------------------------
// test/unit/test_daemon_upgrade_state.cpp
// Shared daemon upgrade state tests
// -----------------------------------------------------------------------------
#include <catch2/catch_test_macros.hpp>
#include "upgrade/daemon_upgrade_state.hpp"
#include <optional>
#include <string>
#include <vector>
namespace {
// -----------------------------------------------------------------------------
// Build one daemon upgrade target for state publication tests.
// -----------------------------------------------------------------------------
DaemonUpgradeTarget
make_target(const std::string &name, const std::string &arch, const std::string &version, const std::string &full_nevra)
{
DaemonUpgradeTarget target;
target.name = name;
target.arch = arch;
target.epoch = "0";
target.version = version;
target.release = "1.fc44";
target.nevra = name + "-" + version + "-1.fc44." + arch;
target.full_nevra = full_nevra;
target.repo_id = "updates";
return target;
}
// -----------------------------------------------------------------------------
// Reset the process-wide state before each test.
// -----------------------------------------------------------------------------
DaemonUpgradeState &
reset_state()
{
DaemonUpgradeState &state = DaemonUpgradeState::instance();
state.reset_for_tests();
return state;
}
} // namespace
// -----------------------------------------------------------------------------
// Verify the default snapshot is unknown, not an empty upgrade list.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade state starts as not loaded")
{
DaemonUpgradeState &state = reset_state();
DaemonUpgradeSnapshot snapshot = state.snapshot();
REQUIRE(snapshot.status == DaemonUpgradeSnapshotStatus::NOT_LOADED);
REQUIRE(snapshot.generation == 0);
REQUIRE(snapshot.targets_by_name_arch.empty());
}
// -----------------------------------------------------------------------------
// Verify that only one daemon upgrade refresh can own the shared state.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade state rejects overlapping refreshes")
{
DaemonUpgradeState &state = reset_state();
std::optional<DaemonUpgradeRefreshId> refresh_id = state.begin_refresh();
REQUIRE(refresh_id.has_value());
REQUIRE_FALSE(state.begin_refresh());
DaemonUpgradeSnapshot snapshot = state.snapshot();
REQUIRE(snapshot.status == DaemonUpgradeSnapshotStatus::REFRESHING);
REQUIRE(snapshot.generation == 0);
REQUIRE(snapshot.targets_by_name_arch.empty());
}
// -----------------------------------------------------------------------------
// Verify that a complete daemon result replaces the shared snapshot.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade state publishes successful targets")
{
DaemonUpgradeState &state = reset_state();
std::string error;
std::vector<DaemonUpgradeTarget> targets {
make_target("demo", "x86_64", "2.0", "demo-0:2.0-1.fc44.x86_64"),
};
std::optional<DaemonUpgradeRefreshId> refresh_id = state.begin_refresh();
REQUIRE(refresh_id.has_value());
REQUIRE(state.publish_success(refresh_id.value(), targets, error) == DaemonUpgradePublishResult::PUBLISHED);
REQUIRE(error.empty());
DaemonUpgradeSnapshot snapshot = state.snapshot();
REQUIRE(snapshot.status == DaemonUpgradeSnapshotStatus::READY);
REQUIRE(snapshot.generation == 1);
REQUIRE(snapshot.targets_by_name_arch.size() == 1);
REQUIRE(snapshot.targets_by_name_arch.count("demo\nx86_64") == 1);
REQUIRE(snapshot.targets_by_name_arch.at("demo\nx86_64").full_nevra == "demo-0:2.0-1.fc44.x86_64");
}
// -----------------------------------------------------------------------------
// Verify that target validation accepts only the current daemon snapshot entry.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade state validates current targets")
{
DaemonUpgradeState &state = reset_state();
std::string error;
DaemonUpgradeTarget target = make_target("demo", "x86_64", "2.0", "demo-0:2.0-1.fc44.x86_64");
std::vector<DaemonUpgradeTarget> targets {
target,
};
std::optional<DaemonUpgradeRefreshId> refresh_id = state.begin_refresh();
REQUIRE(refresh_id.has_value());
REQUIRE(state.publish_success(refresh_id.value(), targets, error) == DaemonUpgradePublishResult::PUBLISHED);
DaemonUpgradeSnapshot snapshot = state.snapshot();
REQUIRE(state.is_current_target(target, snapshot.generation));
DaemonUpgradeTarget changed_target = target;
changed_target.full_nevra = "demo-0:3.0-1.fc44.x86_64";
REQUIRE_FALSE(state.is_current_target(changed_target, snapshot.generation));
REQUIRE_FALSE(state.is_current_target(target, snapshot.generation + 1));
state.mark_stale();
REQUIRE_FALSE(state.is_current_target(target, snapshot.generation));
}
// -----------------------------------------------------------------------------
// Verify that an empty daemon result is a valid ready snapshot.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade state publishes empty successful targets")
{
DaemonUpgradeState &state = reset_state();
std::string error;
std::optional<DaemonUpgradeRefreshId> refresh_id = state.begin_refresh();
REQUIRE(refresh_id.has_value());
REQUIRE(state.publish_success(refresh_id.value(), {}, error) == DaemonUpgradePublishResult::PUBLISHED);
REQUIRE(error.empty());
DaemonUpgradeSnapshot snapshot = state.snapshot();
REQUIRE(snapshot.status == DaemonUpgradeSnapshotStatus::READY);
REQUIRE(snapshot.generation == 1);
REQUIRE(snapshot.targets_by_name_arch.empty());
}
// -----------------------------------------------------------------------------
// Verify that failures do not look like a successful empty daemon result.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade state publishes failure")
{
DaemonUpgradeState &state = reset_state();
std::optional<DaemonUpgradeRefreshId> refresh_id = state.begin_refresh();
REQUIRE(refresh_id.has_value());
state.publish_failure(refresh_id.value());
DaemonUpgradeSnapshot snapshot = state.snapshot();
REQUIRE(snapshot.status == DaemonUpgradeSnapshotStatus::ERROR);
REQUIRE(snapshot.generation == 0);
REQUIRE(snapshot.targets_by_name_arch.empty());
}
// -----------------------------------------------------------------------------
// Verify that stale state is not returned as current upgrade information.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade state marks snapshots stale")
{
DaemonUpgradeState &state = reset_state();
std::string error;
std::vector<DaemonUpgradeTarget> targets {
make_target("demo", "x86_64", "2.0", "demo-0:2.0-1.fc44.x86_64"),
};
std::optional<DaemonUpgradeRefreshId> refresh_id = state.begin_refresh();
REQUIRE(refresh_id.has_value());
REQUIRE(state.publish_success(refresh_id.value(), targets, error) == DaemonUpgradePublishResult::PUBLISHED);
state.mark_stale();
DaemonUpgradeSnapshot snapshot = state.snapshot();
REQUIRE(snapshot.status == DaemonUpgradeSnapshotStatus::STALE);
REQUIRE(snapshot.generation == 1);
REQUIRE(snapshot.targets_by_name_arch.empty());
}
// -----------------------------------------------------------------------------
// Verify that exact duplicate daemon targets are collapsed.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade state collapses exact duplicate targets")
{
DaemonUpgradeState &state = reset_state();
std::string error;
std::vector<DaemonUpgradeTarget> targets {
make_target("demo", "x86_64", "2.0", "demo-0:2.0-1.fc44.x86_64"),
make_target("demo", "x86_64", "2.0", "demo-0:2.0-1.fc44.x86_64"),
};
std::optional<DaemonUpgradeRefreshId> refresh_id = state.begin_refresh();
REQUIRE(refresh_id.has_value());
REQUIRE(state.publish_success(refresh_id.value(), targets, error) == DaemonUpgradePublishResult::PUBLISHED);
DaemonUpgradeSnapshot snapshot = state.snapshot();
REQUIRE(snapshot.status == DaemonUpgradeSnapshotStatus::READY);
REQUIRE(snapshot.generation == 1);
REQUIRE(snapshot.targets_by_name_arch.size() == 1);
}
// -----------------------------------------------------------------------------
// Verify that conflicting daemon targets reject the whole result.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade state rejects conflicting duplicate targets")
{
DaemonUpgradeState &state = reset_state();
std::string error;
std::vector<DaemonUpgradeTarget> first_targets {
make_target("demo", "x86_64", "2.0", "demo-0:2.0-1.fc44.x86_64"),
};
std::vector<DaemonUpgradeTarget> conflicting_targets {
make_target("demo", "x86_64", "2.0", "demo-0:2.0-1.fc44.x86_64"),
make_target("demo", "x86_64", "3.0", "demo-0:3.0-1.fc44.x86_64"),
};
std::optional<DaemonUpgradeRefreshId> first_refresh_id = state.begin_refresh();
REQUIRE(first_refresh_id.has_value());
REQUIRE(state.publish_success(first_refresh_id.value(), first_targets, error) ==
DaemonUpgradePublishResult::PUBLISHED);
std::optional<DaemonUpgradeRefreshId> second_refresh_id = state.begin_refresh();
REQUIRE(second_refresh_id.has_value());
REQUIRE(state.publish_success(second_refresh_id.value(), conflicting_targets, error) ==
DaemonUpgradePublishResult::CONFLICTING_TARGETS);
REQUIRE(error.find("demo.x86_64") != std::string::npos);
DaemonUpgradeSnapshot snapshot = state.snapshot();
REQUIRE(snapshot.status == DaemonUpgradeSnapshotStatus::ERROR);
REQUIRE(snapshot.generation == 1);
REQUIRE(snapshot.targets_by_name_arch.empty());
}
// -----------------------------------------------------------------------------
// Verify that successful publication recovers from error and stale states.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade state recovers after error and stale states")
{
DaemonUpgradeState &state = reset_state();
std::string error;
std::vector<DaemonUpgradeTarget> targets {
make_target("demo", "x86_64", "2.0", "demo-0:2.0-1.fc44.x86_64"),
};
std::optional<DaemonUpgradeRefreshId> failed_refresh_id = state.begin_refresh();
REQUIRE(failed_refresh_id.has_value());
state.publish_failure(failed_refresh_id.value());
error = "old error";
std::optional<DaemonUpgradeRefreshId> error_recovery_id = state.begin_refresh();
REQUIRE(error_recovery_id.has_value());
REQUIRE(state.publish_success(error_recovery_id.value(), targets, error) == DaemonUpgradePublishResult::PUBLISHED);
REQUIRE(error.empty());
REQUIRE(state.snapshot().status == DaemonUpgradeSnapshotStatus::READY);
REQUIRE(state.snapshot().generation == 1);
state.mark_stale();
std::optional<DaemonUpgradeRefreshId> stale_recovery_id = state.begin_refresh();
REQUIRE(stale_recovery_id.has_value());
REQUIRE(state.publish_success(stale_recovery_id.value(), targets, error) == DaemonUpgradePublishResult::PUBLISHED);
REQUIRE(state.snapshot().status == DaemonUpgradeSnapshotStatus::READY);
REQUIRE(state.snapshot().generation == 2);
}
// -----------------------------------------------------------------------------
// Verify that old daemon results cannot publish after refresh ownership is lost.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade state rejects publication after stale")
{
DaemonUpgradeState &state = reset_state();
std::string error;
std::vector<DaemonUpgradeTarget> targets {
make_target("demo", "x86_64", "2.0", "demo-0:2.0-1.fc44.x86_64"),
};
std::optional<DaemonUpgradeRefreshId> refresh_id = state.begin_refresh();
REQUIRE(refresh_id.has_value());
state.mark_stale();
REQUIRE(state.publish_success(refresh_id.value(), targets, error) ==
DaemonUpgradePublishResult::REFRESH_NO_LONGER_ACTIVE);
REQUIRE(error.empty());
state.publish_failure(refresh_id.value());
DaemonUpgradeSnapshot snapshot = state.snapshot();
REQUIRE(snapshot.status == DaemonUpgradeSnapshotStatus::STALE);
REQUIRE(snapshot.generation == 0);
REQUIRE(snapshot.targets_by_name_arch.empty());
}
// -----------------------------------------------------------------------------
// Verify that cancellation can abandon the refresh it owns.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade state abandons active refresh")
{
DaemonUpgradeState &state = reset_state();
std::optional<DaemonUpgradeRefreshId> refresh_id = state.begin_refresh();
REQUIRE(refresh_id.has_value());
REQUIRE(state.abandon_refresh(refresh_id.value()));
DaemonUpgradeSnapshot snapshot = state.snapshot();
REQUIRE(snapshot.status == DaemonUpgradeSnapshotStatus::NOT_LOADED);
REQUIRE(snapshot.generation == 0);
REQUIRE(snapshot.targets_by_name_arch.empty());
}
// -----------------------------------------------------------------------------
// Verify that abandoning a refresh releases ownership for the next refresh.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade state allows refresh after abandon")
{
DaemonUpgradeState &state = reset_state();
std::optional<DaemonUpgradeRefreshId> refresh_id = state.begin_refresh();
REQUIRE(refresh_id.has_value());
REQUIRE(state.abandon_refresh(refresh_id.value()));
std::optional<DaemonUpgradeRefreshId> next_refresh_id = state.begin_refresh();
REQUIRE(next_refresh_id.has_value());
REQUIRE(next_refresh_id.value() != refresh_id.value());
REQUIRE(state.snapshot().status == DaemonUpgradeSnapshotStatus::REFRESHING);
}
// -----------------------------------------------------------------------------
// Verify that abandoning a later refresh of a ready snapshot makes it stale.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade state abandons later refresh as stale")
{
DaemonUpgradeState &state = reset_state();
std::string error;
std::vector<DaemonUpgradeTarget> targets {
make_target("demo", "x86_64", "2.0", "demo-0:2.0-1.fc44.x86_64"),
};
std::optional<DaemonUpgradeRefreshId> first_refresh_id = state.begin_refresh();
REQUIRE(first_refresh_id.has_value());
REQUIRE(state.publish_success(first_refresh_id.value(), targets, error) == DaemonUpgradePublishResult::PUBLISHED);
std::optional<DaemonUpgradeRefreshId> second_refresh_id = state.begin_refresh();
REQUIRE(second_refresh_id.has_value());
REQUIRE(state.abandon_refresh(second_refresh_id.value()));
DaemonUpgradeSnapshot snapshot = state.snapshot();
REQUIRE(snapshot.status == DaemonUpgradeSnapshotStatus::STALE);
REQUIRE(snapshot.generation == 1);
REQUIRE(snapshot.targets_by_name_arch.empty());
}
// -----------------------------------------------------------------------------
// Verify that an old refresh cannot abandon a newer refresh.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade state rejects old abandon during newer refresh")
{
DaemonUpgradeState &state = reset_state();
std::optional<DaemonUpgradeRefreshId> old_refresh_id = state.begin_refresh();
REQUIRE(old_refresh_id.has_value());
state.mark_stale();
std::optional<DaemonUpgradeRefreshId> new_refresh_id = state.begin_refresh();
REQUIRE(new_refresh_id.has_value());
REQUIRE_FALSE(state.abandon_refresh(old_refresh_id.value()));
REQUIRE(state.snapshot().status == DaemonUpgradeSnapshotStatus::REFRESHING);
}
// -----------------------------------------------------------------------------
// Verify that an old successful result cannot replace a newer refresh.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade state rejects old success during newer refresh")
{
DaemonUpgradeState &state = reset_state();
std::string error;
std::vector<DaemonUpgradeTarget> old_targets {
make_target("demo", "x86_64", "2.0", "demo-0:2.0-1.fc44.x86_64"),
};
std::vector<DaemonUpgradeTarget> new_targets {
make_target("demo", "x86_64", "3.0", "demo-0:3.0-1.fc44.x86_64"),
};
std::optional<DaemonUpgradeRefreshId> old_refresh_id = state.begin_refresh();
REQUIRE(old_refresh_id.has_value());
state.mark_stale();
std::optional<DaemonUpgradeRefreshId> new_refresh_id = state.begin_refresh();
REQUIRE(new_refresh_id.has_value());
REQUIRE(state.publish_success(old_refresh_id.value(), old_targets, error) ==
DaemonUpgradePublishResult::REFRESH_NO_LONGER_ACTIVE);
REQUIRE(error.empty());
REQUIRE(state.snapshot().status == DaemonUpgradeSnapshotStatus::REFRESHING);
REQUIRE(state.publish_success(new_refresh_id.value(), new_targets, error) == DaemonUpgradePublishResult::PUBLISHED);
DaemonUpgradeSnapshot snapshot = state.snapshot();
REQUIRE(snapshot.status == DaemonUpgradeSnapshotStatus::READY);
REQUIRE(snapshot.generation == 1);
REQUIRE(snapshot.targets_by_name_arch.at("demo\nx86_64").full_nevra == "demo-0:3.0-1.fc44.x86_64");
}
// -----------------------------------------------------------------------------
// Verify that an old failure cannot replace a newer refresh.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade state ignores old failure during newer refresh")
{
DaemonUpgradeState &state = reset_state();
std::string error;
std::vector<DaemonUpgradeTarget> targets {
make_target("demo", "x86_64", "3.0", "demo-0:3.0-1.fc44.x86_64"),
};
std::optional<DaemonUpgradeRefreshId> old_refresh_id = state.begin_refresh();
REQUIRE(old_refresh_id.has_value());
state.mark_stale();
std::optional<DaemonUpgradeRefreshId> new_refresh_id = state.begin_refresh();
REQUIRE(new_refresh_id.has_value());
state.publish_failure(old_refresh_id.value());
REQUIRE(state.snapshot().status == DaemonUpgradeSnapshotStatus::REFRESHING);
REQUIRE(state.publish_success(new_refresh_id.value(), targets, error) == DaemonUpgradePublishResult::PUBLISHED);
DaemonUpgradeSnapshot snapshot = state.snapshot();
REQUIRE(snapshot.status == DaemonUpgradeSnapshotStatus::READY);
REQUIRE(snapshot.generation == 1);
REQUIRE(snapshot.targets_by_name_arch.at("demo\nx86_64").full_nevra == "demo-0:3.0-1.fc44.x86_64");
}
// -----------------------------------------------------------------------------
// Verify that an old conflicting result reports lost ownership, not target conflict.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade state reports inactive old conflict during newer refresh")
{
DaemonUpgradeState &state = reset_state();
std::string error;
std::vector<DaemonUpgradeTarget> conflicting_targets {
make_target("demo", "x86_64", "2.0", "demo-0:2.0-1.fc44.x86_64"),
make_target("demo", "x86_64", "3.0", "demo-0:3.0-1.fc44.x86_64"),
};
std::optional<DaemonUpgradeRefreshId> old_refresh_id = state.begin_refresh();
REQUIRE(old_refresh_id.has_value());
state.mark_stale();
std::optional<DaemonUpgradeRefreshId> new_refresh_id = state.begin_refresh();
REQUIRE(new_refresh_id.has_value());
REQUIRE(state.publish_success(old_refresh_id.value(), conflicting_targets, error) ==
DaemonUpgradePublishResult::REFRESH_NO_LONGER_ACTIVE);
REQUIRE(error.empty());
DaemonUpgradeSnapshot snapshot = state.snapshot();
REQUIRE(snapshot.status == DaemonUpgradeSnapshotStatus::REFRESHING);
REQUIRE(snapshot.generation == 0);
}
// -----------------------------------------------------------------------------
// Verify that publishing without refresh ownership is rejected.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade state rejects publication without refresh")
{
DaemonUpgradeState &state = reset_state();
std::string error;
std::vector<DaemonUpgradeTarget> targets {
make_target("demo", "x86_64", "2.0", "demo-0:2.0-1.fc44.x86_64"),
};
REQUIRE(state.publish_success(1, targets, error) == DaemonUpgradePublishResult::REFRESH_NO_LONGER_ACTIVE);
REQUIRE(error.empty());
state.publish_failure(1);
DaemonUpgradeSnapshot snapshot = state.snapshot();
REQUIRE(snapshot.status == DaemonUpgradeSnapshotStatus::NOT_LOADED);
REQUIRE(snapshot.generation == 0);
REQUIRE(snapshot.targets_by_name_arch.empty());
}
// -----------------------------------------------------------------------------
// Verify that a discarded refresh owner abandons the active daemon refresh.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade refresh owner abandons discarded results")
{
DaemonUpgradeState &state = reset_state();
std::optional<DaemonUpgradeRefreshId> refresh_id = state.begin_refresh();
REQUIRE(refresh_id.has_value());
{
DaemonUpgradeRefreshOwner owner(refresh_id.value());
}
DaemonUpgradeSnapshot snapshot = state.snapshot();
REQUIRE(snapshot.status == DaemonUpgradeSnapshotStatus::NOT_LOADED);
REQUIRE(state.begin_refresh().has_value());
}
// -----------------------------------------------------------------------------
// Verify that a published refresh owner does not abandon the ready snapshot.
// -----------------------------------------------------------------------------
TEST_CASE("daemon upgrade refresh owner keeps accepted results")
{
DaemonUpgradeState &state = reset_state();
std::string error;
std::vector<DaemonUpgradeTarget> targets {
make_target("demo", "x86_64", "2.0", "demo-0:2.0-1.fc44.x86_64"),
};
std::optional<DaemonUpgradeRefreshId> refresh_id = state.begin_refresh();
REQUIRE(refresh_id.has_value());
{
DaemonUpgradeRefreshOwner owner(refresh_id.value());
REQUIRE(state.publish_success(owner.id(), targets, error) == DaemonUpgradePublishResult::PUBLISHED);
owner.close();
}
DaemonUpgradeSnapshot snapshot = state.snapshot();
REQUIRE(snapshot.status == DaemonUpgradeSnapshotStatus::READY);
REQUIRE(snapshot.generation == 1);
REQUIRE(snapshot.targets_by_name_arch.size() == 1);
}
// -----------------------------------------------------------------------------
// EOF
// -----------------------------------------------------------------------------