22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- import 'package:logging/logging.dart' ;
65import 'package:path/path.dart' as p;
76import 'package:pub_dev/search/search_service.dart' ;
87import 'package:pub_dev/search/updater.dart' ;
@@ -11,44 +10,59 @@ import 'package:pub_dev/service/entrypoint/search_index.dart';
1110import 'package:pub_dev/shared/utils.dart' ;
1211import 'package:test/test.dart' ;
1312
14- final _logger = Logger ('search_index_test' );
15-
1613void main () {
1714 group ('Search index inside an isolate' , () {
18- late IsolateRunner indexRunner;
15+ late IsolateRunner primaryRunner;
16+ late IsolateRunner reducedRunner;
1917
2018 tearDown (() async {
21- await indexRunner.close ();
19+ await primaryRunner.close ();
20+ await reducedRunner.close ();
2221 });
2322
2423 test ('start and work with local index' , () async {
2524 await withTempDirectory ((tempDir) async {
26- final snapshotPath = p.join (tempDir.path, 'index.json.gz' );
25+ // NOTE: The primary and the reduced index loads two different dataset,
26+ // in order to make the testing of the executation path unambigious.
27+ final primaryPath = p.join (tempDir.path, 'primary.json.gz' );
2728 await saveInMemoryPackageIndexToFile (
2829 [
2930 PackageDocument (
3031 package: 'json_annotation' ,
3132 description: 'Annotation metadata for JSON serialization.' ,
33+ tags: ['sdk:dart' ],
3234 ),
3335 ],
34- snapshotPath ,
36+ primaryPath ,
3537 );
3638
37- indexRunner = IsolateRunner .uri (
38- kind: 'index' ,
39- logger: _logger,
40- spawnUri:
41- Uri .parse ('package:pub_dev/service/entrypoint/search_index.dart' ),
42- spawnArgs: ['--snapshot' , snapshotPath],
39+ primaryRunner = await startSearchIsolate (snapshot: primaryPath);
40+
41+ final reducedPath = p.join (tempDir.path, 'reduced.json.gz' );
42+ await saveInMemoryPackageIndexToFile (
43+ [
44+ PackageDocument (
45+ package: 'reduced_json_annotation' ,
46+ description: 'Annotation metadata for JSON serialization.' ,
47+ tags: ['sdk:dart' ],
48+ downloadScore: 1.0 ,
49+ maxPoints: 100 ,
50+ grantedPoints: 100 ,
51+ ),
52+ ],
53+ reducedPath,
4354 );
4455
45- await indexRunner.start (1 );
56+ reducedRunner = await startSearchIsolate (snapshot: reducedPath);
57+
58+ await primaryRunner.start (1 );
59+ await reducedRunner.start (1 );
4660
4761 // index calling the sendport
48- final searchIndex = IsolateSearchIndex (indexRunner );
62+ final searchIndex = IsolateSearchIndex (primaryRunner, reducedRunner );
4963 expect (await searchIndex.isReady (), true );
5064
51- // returns package hit
65+ // text query - result from primary index
5266 final rs =
5367 await searchIndex.search (ServiceSearchQuery .parse (query: 'json' ));
5468 expect (rs.toJson (), {
@@ -62,6 +76,21 @@ void main() {
6276 },
6377 ],
6478 });
79+
80+ // predicate query - result from reduced index
81+ final rs2 = await searchIndex
82+ .search (ServiceSearchQuery .parse (query: 'sdk:dart' ));
83+ expect (rs2.toJson (), {
84+ 'timestamp' : isNotEmpty,
85+ 'totalCount' : 1 ,
86+ 'sdkLibraryHits' : [],
87+ 'packageHits' : [
88+ {
89+ 'package' : 'reduced_json_annotation' ,
90+ 'score' : greaterThan (0.5 ),
91+ },
92+ ],
93+ });
6594 });
6695 }, timeout: Timeout (Duration (minutes: 5 )));
6796 });
0 commit comments