Functional tests for sorted queries