Leon4gr45 commited on
Commit
25566da
·
verified ·
1 Parent(s): b1dcfc2

Delete test/plausible/site/tracker_script_id_cache_test.exs with huggingface_hub

Browse files
test/plausible/site/tracker_script_id_cache_test.exs DELETED
@@ -1,123 +0,0 @@
1
- defmodule Plausible.Site.TrackerScriptIdCacheTest do
2
- use Plausible.DataCase, async: false
3
- @moduletag :ee_only
4
- on_ee do
5
- alias Plausible.Site.TrackerScriptConfiguration
6
- alias Plausible.Site.TrackerScriptIdCache
7
-
8
- describe "public cache interface" do
9
- test "cache caches tracker scripts by id", %{test: test} do
10
- {:ok, _} =
11
- Supervisor.start_link(
12
- [
13
- {TrackerScriptIdCache,
14
- [
15
- cache_name: test,
16
- child_id: :test_cache_tracker_script,
17
- ets_options: [read_concurrency: true]
18
- ]}
19
- ],
20
- strategy: :one_for_one,
21
- name: :"cache_supervisor_#{test}"
22
- )
23
-
24
- site = new_site(domain: "site1.example.com")
25
- config = create_config(site)
26
-
27
- :ok = TrackerScriptIdCache.refresh_all(cache_name: test)
28
-
29
- {:ok, _} = Plausible.Repo.delete(config)
30
-
31
- assert TrackerScriptIdCache.size(test) == 1
32
-
33
- assert TrackerScriptIdCache.get(config.id, force?: true, cache_name: test) == true
34
-
35
- refute TrackerScriptIdCache.get("nonexistent", cache_name: test, force?: true)
36
- end
37
-
38
- test "refresh all and put works", %{test: test} do
39
- {:ok, _} = start_test_cache(test)
40
- site1 = new_site()
41
- site2 = new_site()
42
- site3 = new_site()
43
-
44
- configs = [create_config(site1), create_config(site2)]
45
- cache_opts = [cache_name: test, force?: true]
46
-
47
- for config <- configs do
48
- assert TrackerScriptIdCache.get(config.id, cache_opts) == nil
49
- end
50
-
51
- assert :ok = TrackerScriptIdCache.refresh_all(cache_opts)
52
-
53
- for config <- configs do
54
- result = TrackerScriptIdCache.get(config.id, cache_opts)
55
- assert result == true
56
- end
57
-
58
- new_config = create_config(site3)
59
-
60
- TrackerScriptIdCache.broadcast_put(
61
- new_config.id,
62
- true,
63
- cache_opts
64
- )
65
-
66
- # wait for broadcast put to take effect
67
- assert eventually(fn ->
68
- result = TrackerScriptIdCache.get(new_config.id, cache_opts)
69
- {result == true, result}
70
- end)
71
-
72
- for config <- [new_config | configs] do
73
- result = TrackerScriptIdCache.get(config.id, cache_opts)
74
- assert result == true
75
- end
76
- end
77
-
78
- test "refreshes only recently added configurations", %{test: test} do
79
- {:ok, _} = start_test_cache(test)
80
-
81
- site1 = new_site()
82
- site2 = new_site()
83
-
84
- past_date = ~N[2021-01-01 00:00:00]
85
- old_config = create_config(site1, inserted_at: past_date, updated_at: past_date)
86
- new_config = create_config(site2)
87
-
88
- cache_opts = [cache_name: test, force?: true]
89
-
90
- assert TrackerScriptIdCache.get(old_config.id, cache_opts) == nil
91
- assert TrackerScriptIdCache.get(new_config.id, cache_opts) == nil
92
-
93
- assert :ok = TrackerScriptIdCache.refresh_updated_recently(cache_opts)
94
-
95
- refute TrackerScriptIdCache.get(old_config.id, cache_opts)
96
- assert TrackerScriptIdCache.get(new_config.id, cache_opts)
97
- end
98
- end
99
-
100
- defp start_test_cache(cache_name) do
101
- %{start: {m, f, a}} =
102
- TrackerScriptIdCache.child_spec(cache_name: cache_name, ets_options: [:bag])
103
-
104
- apply(m, f, a)
105
- end
106
-
107
- defp create_config(site, opts \\ []) do
108
- config = %TrackerScriptConfiguration{
109
- site_id: site.id,
110
- installation_type: :manual,
111
- hash_based_routing: true,
112
- outbound_links: true,
113
- file_downloads: true,
114
- form_submissions: true
115
- }
116
-
117
- config
118
- |> Ecto.Changeset.change(opts)
119
- |> Repo.insert!()
120
- |> Repo.preload(:site)
121
- end
122
- end
123
- end