Session tests

This is a rebase of #4279