test/integration/test_index.rb (1531B) - raw
1 require "sup"
2 require "test_helper"
3
4 class TestIndexIntegration < Minitest::Test
5 include Redwood
6
7 def setup
8 @path = Dir.mktmpdir
9 end
10
11 def teardown
12 ObjectSpace.each_object(Class).select {|a| a < Redwood::Singleton}.each do |klass|
13 klass.deinstantiate! unless klass == Redwood::Logger
14 end
15 FileUtils.rm_r @path
16 end
17
18 def create_large_mbox n_messages
19 mbox = File.join @path, "big.mbox"
20 File.open(mbox, "w") do |f|
21 n_messages.times do |i|
22 ## spread the dates out so that the assigned docids are not
23 ## contiguous, as in a real index
24 date = Time.utc(2011) + i * 3600
25 f.write <<EOS
26 From bob@example.com Sat Jan 1 00:00:00 2011
27 From: Bob <bob@example.com>
28 To: Joe <joe@example.com>
29 Subject: message number #{i}
30 Date: #{date.strftime "%a, %d %b %Y %H:%M:%S +0000"}
31 Message-ID: <message-#{i}@example.com>
32
33 Hi Bob, this is test message #{i}. From Joe.
34
35 EOS
36 end
37 end
38 mbox
39 end
40
41 def start_sup_and_add_source source
42 start
43 Logger.remove_sink $stderr
44 Index.init @path
45 Index.load
46 SourceManager.instance.instance_eval '@sources = {}'
47 SourceManager.instance.add_source source
48 PollManager.poll_from source
49 Index.save_index
50 end
51
52 def test_all_mail_query
53 n_messages = 1200
54 mbox = create_large_mbox n_messages
55 start_sup_and_add_source MBox.new "mbox:#{mbox}"
56
57 ## the empty query is the "all mail" listing
58 ids = []
59 Index.each_id({}) { |id| ids << id }
60 assert_equal n_messages, ids.size
61 end
62 end