2 * Copyright (c) 2015, Facebook, Inc.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
11 (* These are basically the same tests as in
12 * test/integration_ml/saved_state/test_naming_table_sqlite_fallback.ml, but
13 * as stripped down to just the basics as possible to make finding the root
14 * cause of test failures easier. *)
18 module Types_pos_asserter
= Asserter.Make_asserter
(struct
19 type t
= FileInfo.pos
* Naming_types.kind_of_type
21 let to_string (pos
, type_of_type
) =
24 (FileInfo.show_pos pos
)
25 (Naming_types.kind_of_type_to_enum type_of_type
)
27 let is_equal = Poly.( = )
30 module Pos_asserter
= Asserter.Make_asserter
(struct
33 let to_string pos
= Printf.sprintf
"(%s)" (FileInfo.show_pos pos
)
35 let is_equal = FileInfo.equal_pos
44 function bar
(): void
{}
54 let write_and_parse_test_files ctx
=
56 List.map
files ~f
:(fun (fn
, contents
) ->
57 (Relative_path.from_root ~suffix
:fn
, contents
))
59 List.iter
files ~f
:(fun (fn
, contents
) ->
60 let fn = Path.make
(Relative_path.to_absolute
fn) in
61 let dir = Path.dirname
fn in
62 Disk.mkdir_p
(Path.to_string dir);
63 Disk.write_file ~file
:(Path.to_string fn) ~contents
);
64 let (file_infos
, errors
, failed_parsing
) =
68 Relative_path.Set.empty
69 ~get_next
:(MultiWorker.next None
(List.map
files ~f
:fst
))
73 if not
(Errors.is_empty errors
) then (
74 Errors.iter_error_list
76 List.iter
(Errors.to_list_ e
) ~f
:(fun (pos
, msg
) ->
80 (Pos.to_absolute
@@ Pos_or_decl.unsafe_to_raw_pos pos
))
83 failwith
"Expected no errors from parsing."
85 if not
(Relative_path.Set.is_empty failed_parsing
) then
86 failwith
"Expected all files to pass parsing.";
87 Naming_table.create file_infos
90 Tempfile.with_real_tempdir
(fun path
->
91 Relative_path.set_path_prefix
93 (Path.concat path
"root/");
98 heap_size
= 1024 * 1024;
102 shm_use_sharded_hashtbl
= false;
109 let (_
: SharedMem.handle
) = SharedMem.init
config ~num_workers
:0 in
111 Provider_context.empty_for_test
112 ~popt
:ParserOptions.default
113 ~tcopt
:TypecheckerOptions.default
114 ~deps_mode
:Typing_deps_mode.SQLiteMode
117 let unbacked_naming_table = write_and_parse_test_files ctx in
118 let db_name = Path.to_string (Path.concat path
"naming_table.sqlite") in
119 let save_results = Naming_table.save
unbacked_naming_table db_name in
120 Asserter.Int_asserter.assert_equals
122 Naming_sqlite.(save_results.files_added
+ save_results.symbols_added
)
123 "Expected to add eight rows (four files and four symbols)";
124 let (_backed_naming_table
: Naming_table.t
) =
125 Naming_table.load_from_sqlite
ctx db_name
130 let test_dep_graph_blob () =
132 Tempfile.with_tempdir
@@ fun dir ->
133 let workers = None
in
134 let delegate_state = Typing_service_delegate.default
in
135 let opts = TypecheckerOptions.default
in
136 let dynamic_view_files = Relative_path.Set.empty
in
137 let memory_cap = None
in
139 Typing_service_types.
144 profile_type_check_duration_threshold
= 0.0;
145 profile_type_check_memory_threshold_mb
= 0;
146 profile_type_check_twice
= false;
147 profile_decling
= Typing_service_types.DeclingOff
;
151 Provider_context.empty_for_test
152 ~popt
:ParserOptions.default
154 ~deps_mode
:Typing_deps_mode.SQLiteMode
157 (* Check reentrancy *)
159 let { Typing_check_service.errors
; _
} =
160 Typing_check_service.go
164 (Telemetry.create
())
166 [Relative_path.from_root ~suffix
:"baz.php"]
168 ~longlived_workers
:false
169 ~remote_execution
:None
173 Asserter.Bool_asserter.assert_equals
175 (Errors.is_empty errors
)
176 "Unexpected type errors";
178 Asserter.Int_asserter.assert_equals
180 (SharedMem.get_in_memory_dep_table_entry_count
())
181 "Expected the correct # of edges in memory after saving dep table blob";
183 let filename = Path.(to_string (concat
dir "deptable.bin")) in
185 SharedMem.save_dep_table_blob
188 ~reset_state_after_saving
:true
191 Asserter.Int_asserter.assert_equals
194 "Expected # of edges to be correct";
196 Asserter.Int_asserter.assert_equals
198 (SharedMem.get_in_memory_dep_table_entry_count
())
199 "Expected 0 edges in memory after saving dep table blob"
202 let () = Unit_test.run_all
[("test_dep_graph_blob", test_dep_graph_blob)]