~jan-kneschke/mysql-proxy/packet-tracking-assertions

« back to all changes in this revision

Viewing changes to tests/suite/base/t/bug_35729-test.lua

  • Committer: Kay Roepke
  • Author(s): Jan Kneschke
  • Date: 2008-01-23 22:00:28 UTC
  • Revision ID: kay@mysql.com-20080123220028-hq2xqb69apa75fnx
first round on mysql-shell based on the proxy code

this is mostly a verification if the proxy-code is flexible enough to handle 
all three scenarios of: client, server and forwarding (proxy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
---
2
 
--
3
 
--
4
 
 
5
 
---
6
 
function read_query( packet )
7
 
        if packet:byte() == proxy.COM_QUERY then
8
 
                proxy.queries:append(1, packet, { resultset_is_needed = true } )
9
 
                return proxy.PROXY_SEND_QUERY
10
 
        end
11
 
end
12
 
 
13
 
---
14
 
--
15
 
--
16
 
function read_query_result(inj)
17
 
        local fields = inj.resultset.fields
18
 
        collectgarbage("collect") -- trigger a full GC
19
 
 
20
 
        assert(type(fields) == "userdata")
21
 
        assert(type(fields[1]) == "userdata") -- if the GC removed the underlying c-struct, fields[1] will be nil 
22
 
 
23
 
        proxy.response = {
24
 
                type = proxy.MYSQLD_PACKET_OK,
25
 
                resultset = {
26
 
                        fields = { },
27
 
                        rows = { }
28
 
                }
29
 
        }
30
 
 
31
 
        proxy.response.resultset.fields[1] = {
32
 
                name = fields[1].name, type = fields[1].type
33
 
        }
34
 
        proxy.response.resultset.fields[2] = {
35
 
                name = fields[2].name, type = fields[2].type
36
 
        }
37
 
        for row in inj.resultset.rows do
38
 
                collectgarbage("collect") -- trigger a full GC
39
 
 
40
 
                ---
41
 
                -- if something goes wrong 'row' will reference a free()ed old resultset now
42
 
                -- leading to nil here
43
 
                proxy.response.resultset.rows[#proxy.response.resultset.rows + 1] = { row[1], row[2] }
44
 
        end
45
 
 
46
 
        return proxy.PROXY_SEND_RESULT
47
 
end